Skip to content

Commit a3f828f

Browse files
authored
feat: support 2 more platforms (#39)
* feat: support 2 more platforms * fix
1 parent 908bb09 commit a3f828f

File tree

10 files changed

+317
-385
lines changed

10 files changed

+317
-385
lines changed

.github/workflows/CI.yml

Lines changed: 69 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ jobs:
6363
- host: ubuntu-latest
6464
target: aarch64-unknown-linux-musl
6565
build: yarn build --target aarch64-unknown-linux-musl -x
66+
- host: ubuntu-latest
67+
target: powerpc64le-unknown-linux-gnu
68+
build: |
69+
sudo apt-get update
70+
sudo apt-get install -y gcc-powerpc64le-linux-gnu
71+
yarn build --target powerpc64le-unknown-linux-gnu
72+
- host: ubuntu-latest
73+
target: s390x-unknown-linux-gnu
74+
build: |
75+
sudo apt-get update
76+
sudo apt-get install -y gcc-s390x-linux-gnu
77+
yarn build --target s390x-unknown-linux-gnu
6678
- host: windows-latest
6779
target: aarch64-pc-windows-msvc
6880
build: yarn build --target aarch64-pc-windows-msvc
@@ -95,16 +107,21 @@ jobs:
95107
uses: actions/cache@v4
96108
with:
97109
path: |
98-
~/.cargo/registry/index/
99-
~/.cargo/registry/cache/
100-
~/.cargo/git/db/
110+
~/.cargo
101111
~/.napi-rs
102112
target/
103113
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
104114
- uses: goto-bus-stop/setup-zig@v2
105115
if: ${{ contains(matrix.settings.target, 'musl') }}
106116
with:
107117
version: 0.13.0
118+
- name: Install cargo-zigbuild
119+
uses: taiki-e/install-action@v2
120+
if: ${{ contains(matrix.settings.target, 'musl') }}
121+
env:
122+
GITHUB_TOKEN: ${{ github.token }}
123+
with:
124+
tool: cargo-zigbuild
108125
- name: Setup toolchain
109126
run: ${{ matrix.settings.setup }}
110127
if: ${{ matrix.settings.setup }}
@@ -219,16 +236,30 @@ jobs:
219236
shell: bash
220237
- name: Test bindings
221238
run: yarn test
222-
test-linux-x64-gnu-binding:
223-
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
239+
test-linux-binding:
240+
name: Test ${{ matrix.target }} - node@${{ matrix.node }}
224241
needs:
225242
- build
226243
strategy:
227244
fail-fast: false
228245
matrix:
246+
target:
247+
- x86_64-unknown-linux-gnu
248+
- x86_64-unknown-linux-musl
249+
- aarch64-unknown-linux-gnu
250+
- aarch64-unknown-linux-musl
251+
- armv7-unknown-linux-gnueabihf
252+
- s390x-unknown-linux-gnu
253+
- powerpc64le-unknown-linux-gnu
229254
node:
230255
- '18'
231256
- '20'
257+
exclude:
258+
# too slow
259+
- target: aarch64-unknown-linux-gnu
260+
node: '18'
261+
- target: s390x-unknown-linux-gnu
262+
node: '18'
232263
runs-on: ubuntu-latest
233264
steps:
234265
- uses: actions/checkout@v4
@@ -237,162 +268,55 @@ jobs:
237268
with:
238269
node-version: ${{ matrix.node }}
239270
cache: yarn
240-
- name: Install dependencies
241-
run: yarn install
242-
- name: Download artifacts
243-
uses: actions/download-artifact@v4
244-
with:
245-
name: bindings-x86_64-unknown-linux-gnu
246-
path: .
247-
- name: List packages
248-
run: ls -R .
249-
shell: bash
250-
- name: Test bindings
251-
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
252-
test-linux-x64-musl-binding:
253-
name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
254-
needs:
255-
- build
256-
strategy:
257-
fail-fast: false
258-
matrix:
259-
node:
260-
- '18'
261-
- '20'
262-
runs-on: ubuntu-latest
263-
steps:
264-
- uses: actions/checkout@v4
265-
- name: Setup node
266-
uses: actions/setup-node@v4
267-
with:
268-
node-version: ${{ matrix.node }}
269-
cache: yarn
270-
- name: Install dependencies
271-
run: |
272-
yarn config set supportedArchitectures.libc "musl"
273-
yarn install
274-
- name: Download artifacts
275-
uses: actions/download-artifact@v4
276-
with:
277-
name: bindings-x86_64-unknown-linux-musl
278-
path: .
279-
- name: List packages
280-
run: ls -R .
281-
shell: bash
282-
- name: Test bindings
283-
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn test
284-
test-linux-aarch64-gnu-binding:
285-
name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
286-
needs:
287-
- build
288-
strategy:
289-
fail-fast: false
290-
matrix:
291-
node:
292-
- '18'
293-
- '20'
294-
runs-on: ubuntu-latest
295-
steps:
296-
- uses: actions/checkout@v4
297-
- name: Download artifacts
298-
uses: actions/download-artifact@v4
299-
with:
300-
name: bindings-aarch64-unknown-linux-gnu
301-
path: .
302-
- name: List packages
303-
run: ls -R .
304-
shell: bash
305-
- name: Install dependencies
271+
- name: Output docker params
272+
id: docker
306273
run: |
307-
yarn config set supportedArchitectures.cpu "arm64"
308-
yarn config set supportedArchitectures.libc "glibc"
309-
yarn install
310-
- name: Set up QEMU
311-
uses: docker/setup-qemu-action@v3
312-
with:
313-
platforms: arm64
314-
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
315-
- name: Setup and run tests
316-
uses: addnab/docker-run-action@v3
317-
with:
318-
image: node:${{ matrix.node }}-slim
319-
options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
320-
run: |
321-
set -e
322-
yarn test
323-
ls -la
324-
test-linux-aarch64-musl-binding:
325-
name: Test bindings on aarch64-unknown-linux-musl - node@lts
326-
needs:
327-
- build
328-
runs-on: ubuntu-latest
329-
steps:
330-
- uses: actions/checkout@v4
331-
- name: Download artifacts
332-
uses: actions/download-artifact@v4
333-
with:
334-
name: bindings-aarch64-unknown-linux-musl
335-
path: .
336-
- name: List packages
337-
run: ls -R .
338-
shell: bash
274+
node -e "
275+
if ('${{ matrix.target }}'.startsWith('aarch64')) {
276+
console.log('PLATFORM=linux/arm64')
277+
} else if ('${{ matrix.target }}'.startsWith('armv7')) {
278+
console.log('PLATFORM=linux/arm/v7')
279+
} else if ('${{ matrix.target }}'.startsWith('powerpc64le')) {
280+
console.log('PLATFORM=linux/ppc64le')
281+
} else if ('${{ matrix.target }}'.startsWith('s390x')) {
282+
console.log('PLATFORM=linux/s390x')
283+
} else {
284+
console.log('PLATFORM=linux/amd64')
285+
}
286+
" >> $GITHUB_OUTPUT
287+
node -e "
288+
if ('${{ matrix.target }}'.endsWith('-musl')) {
289+
console.log('IMAGE=node:${{ matrix.node }}-alpine')
290+
} else {
291+
console.log('IMAGE=node:${{ matrix.node }}-slim')
292+
}
293+
" >> $GITHUB_OUTPUT
339294
- name: Install dependencies
340295
run: |
341-
yarn config set supportedArchitectures.cpu "arm64"
342-
yarn config set supportedArchitectures.libc "musl"
296+
yarn config set --json supportedArchitectures.os '["current", "linux"]'
297+
yarn config set --json supportedArchitectures.cpu '["current", "arm64", "arm", "ppc64", "s390x", "x64"]'
298+
yarn config set --json supportedArchitectures.libc '["current", "glibc", "musl"]'
343299
yarn install
344-
- name: Set up QEMU
345-
uses: docker/setup-qemu-action@v3
346-
with:
347-
platforms: arm64
348-
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
349-
- name: Setup and run tests
350-
uses: addnab/docker-run-action@v3
351-
with:
352-
image: node:lts-alpine
353-
options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
354-
run: |
355-
set -e
356-
yarn test
357-
test-linux-arm-gnueabihf-binding:
358-
name: Test bindings on armv7-unknown-linux-gnueabihf - node@${{ matrix.node }}
359-
needs:
360-
- build
361-
strategy:
362-
fail-fast: false
363-
matrix:
364-
node:
365-
- '18'
366-
- '20'
367-
runs-on: ubuntu-latest
368-
steps:
369-
- uses: actions/checkout@v4
370300
- name: Download artifacts
371301
uses: actions/download-artifact@v4
372302
with:
373-
name: bindings-armv7-unknown-linux-gnueabihf
303+
name: bindings-${{ matrix.target }}
374304
path: .
375305
- name: List packages
376306
run: ls -R .
377307
shell: bash
378-
- name: Install dependencies
379-
run: |
380-
yarn config set supportedArchitectures.cpu "arm"
381-
yarn install
382308
- name: Set up QEMU
383309
uses: docker/setup-qemu-action@v3
384310
with:
385-
platforms: arm
311+
platforms: all
386312
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
387-
- name: Setup and run tests
313+
- name: Test bindings
388314
uses: addnab/docker-run-action@v3
389315
with:
390-
image: node:${{ matrix.node }}-slim
391-
options: '--platform linux/arm/v7 -v ${{ github.workspace }}:/build -w /build'
392-
run: |
393-
set -e
394-
yarn test
395-
ls -la
316+
image: ${{ steps.docker.outputs.IMAGE }}
317+
options: -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }}
318+
run: yarn run test
319+
396320
test-nodejs-wasi:
397321
name: Test bindings on wasm32-wasi - node@${{ matrix.node }}
398322
needs:
@@ -431,11 +355,7 @@ jobs:
431355
needs:
432356
- build-freebsd
433357
- test-macOS-windows-binding
434-
- test-linux-x64-gnu-binding
435-
- test-linux-x64-musl-binding
436-
- test-linux-aarch64-gnu-binding
437-
- test-linux-aarch64-musl-binding
438-
- test-linux-arm-gnueabihf-binding
358+
- test-linux-binding
439359
- test-nodejs-wasi
440360
steps:
441361
- uses: actions/checkout@v4

__test__/index.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { join } from 'node:path'
44
import test from 'ava'
55

66
import { Archive } from '../index'
7+
import { fileURLToPath } from 'node:url'
8+
9+
const __dirname = join(fileURLToPath(import.meta.url), '..')
710

811
test('should be able to read archive', (t) => {
912
const archive = new Archive(join(__dirname, 'src.tar'))

__test__/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

__test__/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"module": "ESNext",
5+
"moduleResolution": "Bundler",
6+
"outDir": "./dist"
7+
},
8+
"include": ["."],
9+
"exclude": []
10+
}

benchmark/bench.ts

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { readFileSync } from 'node:fs'
22
import { join } from 'node:path'
33

4-
import b from 'benny'
4+
import { Bench } from 'tinybench'
55
import { list } from 'tar'
66

77
import { Archive } from '../index'
8+
import { fileURLToPath } from 'node:url'
9+
10+
const __dirname = join(fileURLToPath(import.meta.url), '..')
811

912
const ARCHIVE_PATH = join(__dirname, '..', '__test__', 'src.tar.gz')
1013

@@ -22,33 +25,26 @@ for (const entry of archive.entries()) {
2225
console.info('list from @napi-rs/tar', entry.path())
2326
}
2427

25-
async function run() {
26-
await b.suite(
27-
'Read all entries',
28-
29-
b.add('@napi-rs/tar', () => {
30-
const archiveBuffer = readFileSync(ARCHIVE_PATH)
31-
const archive = new Archive(archiveBuffer)
32-
for (const entry of archive.entries()) {
33-
entry.path()
34-
}
35-
}),
36-
37-
b.add('node-tar', () => {
38-
list({
39-
file: join(__dirname, '..', '__test__', 'src.tar.gz'),
40-
onentry: (entry) => {
41-
entry.path
42-
},
43-
sync: true,
44-
})
45-
}),
46-
47-
b.cycle(),
48-
b.complete(),
49-
)
50-
}
28+
const b = new Bench()
29+
30+
b.add('@napi-rs/tar', () => {
31+
const archiveBuffer = readFileSync(ARCHIVE_PATH)
32+
const archive = new Archive(archiveBuffer)
33+
for (const entry of archive.entries()) {
34+
entry.path()
35+
}
36+
})
5137

52-
run().catch((e) => {
53-
console.error(e)
38+
b.add('node-tar', () => {
39+
list({
40+
file: join(__dirname, '..', '__test__', 'src.tar.gz'),
41+
onentry: (entry) => {
42+
entry.path
43+
},
44+
sync: true,
45+
})
5446
})
47+
48+
await b.run()
49+
50+
console.table(b.table())

benchmark/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

benchmark/tsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "../__test__/tsconfig.json",
3+
"include": ["."],
4+
"exclude": []
5+
}

0 commit comments

Comments
 (0)