Skip to content

Commit 9545a2c

Browse files
committed
add support for more platforms, fix pypi and npm publish
1 parent 5100482 commit 9545a2c

9 files changed

Lines changed: 565 additions & 51 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ jobs:
4040
- name: Run tests
4141
run: cargo test --workspace
4242

43+
dispatch-tests:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
48+
49+
- name: Setup Node.js
50+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
51+
with:
52+
node-version: '20'
53+
54+
- name: Run npm dispatch tests
55+
run: node --test npm/socket-patch/bin/socket-patch.test.mjs
56+
57+
- name: Setup Python
58+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
59+
with:
60+
python-version: '3.12'
61+
62+
- name: Run pypi dispatch tests
63+
run: python pypi/socket-patch/test_dispatch.py
64+
4365
e2e:
4466
needs: test
4567
strategy:

.github/workflows/release.yml

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,26 @@ jobs:
8080
runner: windows-latest
8181
archive: zip
8282
build-tool: cargo
83+
- target: i686-pc-windows-msvc
84+
runner: windows-latest
85+
archive: zip
86+
build-tool: cargo
87+
- target: aarch64-pc-windows-msvc
88+
runner: windows-latest
89+
archive: zip
90+
build-tool: cargo
91+
- target: aarch64-linux-android
92+
runner: ubuntu-latest
93+
archive: tar.gz
94+
build-tool: cross
95+
- target: arm-unknown-linux-gnueabihf
96+
runner: ubuntu-latest
97+
archive: tar.gz
98+
build-tool: cross
99+
- target: i686-unknown-linux-gnu
100+
runner: ubuntu-latest
101+
archive: tar.gz
102+
build-tool: cross
83103
runs-on: ${{ matrix.runner }}
84104
steps:
85105
- name: Checkout
@@ -213,8 +233,10 @@ jobs:
213233
- name: Setup Node.js
214234
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
215235
with:
216-
node-version: '20'
217-
registry-url: 'https://registry.npmjs.org'
236+
node-version: '22'
237+
238+
- name: Update npm for trusted publishing
239+
run: npm install -g npm@latest
218240

219241
- name: Stage binaries
220242
run: |
@@ -227,16 +249,24 @@ jobs:
227249
mv npm/socket-patch/bin/socket-patch npm/socket-patch/bin/socket-patch-linux-x64
228250
tar xzf artifacts/socket-patch-aarch64-unknown-linux-gnu.tar.gz -C npm/socket-patch/bin/
229251
mv npm/socket-patch/bin/socket-patch npm/socket-patch/bin/socket-patch-linux-arm64
252+
tar xzf artifacts/socket-patch-arm-unknown-linux-gnueabihf.tar.gz -C npm/socket-patch/bin/
253+
mv npm/socket-patch/bin/socket-patch npm/socket-patch/bin/socket-patch-linux-arm
254+
tar xzf artifacts/socket-patch-i686-unknown-linux-gnu.tar.gz -C npm/socket-patch/bin/
255+
mv npm/socket-patch/bin/socket-patch npm/socket-patch/bin/socket-patch-linux-ia32
256+
tar xzf artifacts/socket-patch-aarch64-linux-android.tar.gz -C npm/socket-patch/bin/
257+
mv npm/socket-patch/bin/socket-patch npm/socket-patch/bin/socket-patch-android-arm64
230258
cd npm/socket-patch/bin
231259
unzip ../../../artifacts/socket-patch-x86_64-pc-windows-msvc.zip
232260
mv socket-patch.exe socket-patch-win32-x64.exe
261+
unzip ../../../artifacts/socket-patch-i686-pc-windows-msvc.zip
262+
mv socket-patch.exe socket-patch-win32-ia32.exe
263+
unzip ../../../artifacts/socket-patch-aarch64-pc-windows-msvc.zip
264+
mv socket-patch.exe socket-patch-win32-arm64.exe
233265
234266
- name: Copy README for npm package
235267
run: cp README.md npm/socket-patch/README.md
236268

237269
- name: Publish package
238-
env:
239-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
240270
run: npm publish ./npm/socket-patch --provenance --access public
241271

242272
pypi-publish:
@@ -262,38 +292,12 @@ jobs:
262292
with:
263293
python-version: '3.12'
264294

265-
- name: Install build tools
266-
run: pip install build
267-
268-
- name: Stage binaries
269-
run: |
270-
mkdir -p pypi/socket-patch/socket_patch/bin
271-
tar xzf artifacts/socket-patch-aarch64-apple-darwin.tar.gz -C pypi/socket-patch/socket_patch/bin/
272-
mv pypi/socket-patch/socket_patch/bin/socket-patch pypi/socket-patch/socket_patch/bin/socket-patch-darwin-arm64
273-
tar xzf artifacts/socket-patch-x86_64-apple-darwin.tar.gz -C pypi/socket-patch/socket_patch/bin/
274-
mv pypi/socket-patch/socket_patch/bin/socket-patch pypi/socket-patch/socket_patch/bin/socket-patch-darwin-x64
275-
tar xzf artifacts/socket-patch-x86_64-unknown-linux-musl.tar.gz -C pypi/socket-patch/socket_patch/bin/
276-
mv pypi/socket-patch/socket_patch/bin/socket-patch pypi/socket-patch/socket_patch/bin/socket-patch-linux-x64
277-
tar xzf artifacts/socket-patch-aarch64-unknown-linux-gnu.tar.gz -C pypi/socket-patch/socket_patch/bin/
278-
mv pypi/socket-patch/socket_patch/bin/socket-patch pypi/socket-patch/socket_patch/bin/socket-patch-linux-arm64
279-
cd pypi/socket-patch/socket_patch/bin
280-
unzip ../../../../artifacts/socket-patch-x86_64-pc-windows-msvc.zip
281-
mv socket-patch.exe socket-patch-win32-x64.exe
282-
283-
- name: Set executable permissions
295+
- name: Build platform wheels
284296
run: |
285-
chmod +x pypi/socket-patch/socket_patch/bin/socket-patch-darwin-arm64
286-
chmod +x pypi/socket-patch/socket_patch/bin/socket-patch-darwin-x64
287-
chmod +x pypi/socket-patch/socket_patch/bin/socket-patch-linux-x64
288-
chmod +x pypi/socket-patch/socket_patch/bin/socket-patch-linux-arm64
289-
290-
- name: Copy README for PyPI package
291-
run: cp README.md pypi/socket-patch/README.md
292-
293-
- name: Build package
294-
run: python -m build pypi/socket-patch
297+
VERSION="${{ needs.sync-and-tag.outputs.version }}"
298+
python scripts/build-pypi-wheels.py --version "$VERSION" --artifacts artifacts --dist dist
295299
296300
- name: Publish to PyPI
297301
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
298302
with:
299-
packages-dir: pypi/socket-patch/dist/
303+
packages-dir: dist/

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm/socket-patch/bin/socket-patch

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ const BINARIES = {
77
"darwin x64": "socket-patch-darwin-x64",
88
"linux x64": "socket-patch-linux-x64",
99
"linux arm64": "socket-patch-linux-arm64",
10+
"linux arm": "socket-patch-linux-arm",
11+
"linux ia32": "socket-patch-linux-ia32",
1012
"win32 x64": "socket-patch-win32-x64.exe",
13+
"win32 ia32": "socket-patch-win32-ia32.exe",
14+
"win32 arm64": "socket-patch-win32-arm64.exe",
15+
"android arm64": "socket-patch-android-arm64",
1116
};
1217

1318
const key = `${process.platform} ${process.arch}`;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { describe, it } from "node:test";
2+
import assert from "node:assert/strict";
3+
import { readFileSync } from "node:fs";
4+
import { fileURLToPath } from "node:url";
5+
import { dirname, join } from "node:path";
6+
7+
const __dirname = dirname(fileURLToPath(import.meta.url));
8+
const src = readFileSync(join(__dirname, "socket-patch"), "utf8");
9+
10+
// Extract the BINARIES object from the source
11+
const match = src.match(/const BINARIES = \{([\s\S]*?)\};/);
12+
assert.ok(match, "BINARIES object not found in socket-patch");
13+
14+
// Parse keys and values from the object literal
15+
const entries = [...match[1].matchAll(/"([^"]+)":\s*"([^"]+)"/g)].map(
16+
([, key, value]) => [key, value]
17+
);
18+
const BINARIES = Object.fromEntries(entries);
19+
20+
const EXPECTED_KEYS = [
21+
"darwin arm64",
22+
"darwin x64",
23+
"linux x64",
24+
"linux arm64",
25+
"linux arm",
26+
"linux ia32",
27+
"win32 x64",
28+
"win32 ia32",
29+
"win32 arm64",
30+
"android arm64",
31+
];
32+
33+
describe("npm platform dispatch", () => {
34+
it("has all expected platform keys", () => {
35+
for (const key of EXPECTED_KEYS) {
36+
assert.ok(BINARIES[key], `missing platform key: ${key}`);
37+
}
38+
});
39+
40+
it("has no unexpected platform keys", () => {
41+
for (const key of Object.keys(BINARIES)) {
42+
assert.ok(EXPECTED_KEYS.includes(key), `unexpected platform key: ${key}`);
43+
}
44+
});
45+
46+
it("binary names follow socket-patch-<platform>-<arch>[.exe] convention", () => {
47+
for (const [key, bin] of Object.entries(BINARIES)) {
48+
const [platform, arch] = key.split(" ");
49+
const expected = platform === "win32"
50+
? `socket-patch-${platform}-${arch}.exe`
51+
: `socket-patch-${platform}-${arch}`;
52+
assert.equal(bin, expected, `binary name mismatch for ${key}`);
53+
}
54+
});
55+
56+
it("windows entries end in .exe", () => {
57+
for (const [key, bin] of Object.entries(BINARIES)) {
58+
if (key.startsWith("win32")) {
59+
assert.ok(bin.endsWith(".exe"), `${key} should end in .exe`);
60+
}
61+
}
62+
});
63+
64+
it("non-windows entries do not end in .exe", () => {
65+
for (const [key, bin] of Object.entries(BINARIES)) {
66+
if (!key.startsWith("win32")) {
67+
assert.ok(!bin.endsWith(".exe"), `${key} should not end in .exe`);
68+
}
69+
}
70+
});
71+
});
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import os
22
import sys
33
import subprocess
4-
import platform
5-
6-
BINARIES = {
7-
("darwin", "arm64"): "socket-patch-darwin-arm64",
8-
("darwin", "x86_64"): "socket-patch-darwin-x64",
9-
("linux", "x86_64"): "socket-patch-linux-x64",
10-
("linux", "aarch64"): "socket-patch-linux-arm64",
11-
("win32", "amd64"): "socket-patch-win32-x64.exe",
12-
}
134

145

156
def main():
16-
machine = platform.machine().lower()
17-
key = (sys.platform, machine)
18-
bin_name = BINARIES.get(key)
19-
if not bin_name:
20-
print(f"Unsupported platform: {sys.platform} {machine}", file=sys.stderr)
7+
bin_dir = os.path.join(os.path.dirname(__file__), "bin")
8+
try:
9+
entries = os.listdir(bin_dir)
10+
except OSError:
11+
entries = []
12+
bins = [e for e in entries if e.startswith("socket-patch")]
13+
if len(bins) != 1:
14+
print(
15+
f"Expected exactly one socket-patch binary in {bin_dir}, found {len(bins)}",
16+
file=sys.stderr,
17+
)
2118
sys.exit(1)
22-
bin_path = os.path.join(os.path.dirname(__file__), "bin", bin_name)
19+
bin_path = os.path.join(bin_dir, bins[0])
2320
raise SystemExit(subprocess.call([bin_path] + sys.argv[1:]))

0 commit comments

Comments
 (0)