Skip to content

Commit

Permalink
ci: wasm32-wasi target rename (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed May 13, 2024
1 parent c505d04 commit afc909f
Show file tree
Hide file tree
Showing 14 changed files with 1,419 additions and 1,462 deletions.
38 changes: 21 additions & 17 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ jobs:
fail-fast: false
matrix:
settings:
- host: macos-14
- host: macos-latest
target: x86_64-apple-darwin
setup: |
brew install meson llvm
build: |
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
export PATH="$(brew --prefix llvm)/bin:$PATH"
export CC=clang
export CXX=clang++
export CMAKE_BUILD_PARALLEL_LEVEL=2
Expand All @@ -46,8 +46,9 @@ jobs:
python -m pip install meson
yarn workspace @napi-rs/image build --target x86_64-pc-windows-msvc --features with_simd
target: x86_64-pc-windows-msvc
- host: macos-14
- host: macos-latest
setup: |
brew update
brew install meson llvm
cargo install cargo-xwin
build: |
Expand All @@ -56,7 +57,7 @@ jobs:
export CFLAGS="-mavx2 -mpclmul"
export CXXFLAGS="-mavx2 -mpclmul"
export CARGO_PROFILE_RELEASE_LTO="false"
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
export PATH="$(brew --prefix llvm)/bin:$PATH"
clang --version
CARGO="cargo-xwin" yarn workspace @napi-rs/image build --features with_simd --target i686-pc-windows-msvc
target: i686-pc-windows-msvc
Expand Down Expand Up @@ -90,16 +91,19 @@ jobs:
- host: macos-latest
target: aarch64-apple-darwin
setup: |
brew update
brew install meson llvm
build: |
export PATH="/usr/local/opt/llvm/bin:$PATH"
export PATH="$(brew --prefix llvm)/bin:$PATH"
export MACOSX_DEPLOYMENT_TARGET='11.0'
export CMAKE_BUILD_PARALLEL_LEVEL=2
export CC=clang
export CXX=clang++
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS="16"
export CARGO_PROFILE_RELEASE_LTO="thin"
export CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER="clang"
clang --version
yarn workspace @napi-rs/image build --target aarch64-apple-darwin --features with_simd -- -vvv
yarn workspace @napi-rs/image build --target aarch64-apple-darwin --features with_simd
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
Expand Down Expand Up @@ -136,15 +140,15 @@ jobs:
apk add --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing --no-cache aom-dev perl meson &&
yarn workspace @napi-rs/image build --target aarch64-unknown-linux-musl --features with_simd &&
chmod -R 777 target
- host: macos-14
target: wasm32-wasi-preview1-threads
- host: macos-latest
target: wasm32-wasip1-threads
setup: |
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-21/wasi-sdk-21.0-macos.tar.gz
tar -xvf wasi-sdk-21.0-macos.tar.gz
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0-macos.tar.gz
tar -xvf wasi-sdk-22.0-macos.tar.gz
build: |
export WASI_SDK_PATH="$(pwd)/wasi-sdk-21.0"
export WASI_SDK_PATH="$(pwd)/wasi-sdk-22.0"
export CMAKE_BUILD_PARALLEL_LEVEL=2
yarn workspace @napi-rs/image build --target wasm32-wasi-preview1-threads
yarn workspace @napi-rs/image build --target wasm32-wasip1-threads
name: stable - ${{ matrix.settings.target }} - node@20
runs-on: ${{ matrix.settings.host }}
Expand Down Expand Up @@ -180,7 +184,7 @@ jobs:
- uses: goto-bus-stop/setup-zig@v2
if: ${{ contains(matrix.settings.target, 'musl') }}
with:
version: 0.11.0
version: 0.12.0
- name: Setup toolchain
run: ${{ matrix.settings.setup }}
if: ${{ matrix.settings.setup }}
Expand Down Expand Up @@ -265,9 +269,9 @@ jobs:
settings:
- host: windows-latest
target: x86_64-pc-windows-msvc
- host: macos-14
- host: macos-latest
target: x86_64-apple-darwin
- host: macos-14
- host: macos-latest
target: aarch64-apple-darwin
node:
- '18'
Expand Down Expand Up @@ -451,15 +455,15 @@ jobs:
run: yarn test
test-wasi-on-nodejs:
name: Test wasi on Node.js
runs-on: macos-14
runs-on: macos-latest
needs:
- build
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-wasm32-wasi-preview1-threads
name: bindings-wasm32-wasip1-threads
path: artifacts
- name: Install dependencies
run: yarn install --immutable --mode=skip-build
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
"website"
],
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.41",
"@napi-rs/cli": "^3.0.0-alpha.55",
"@taplo/cli": "^0.7.0",
"@types/node": "^20.11.16",
"@types/node": "^20.12.11",
"@types/sharp": "^0.32.0",
"ava": "^6.1.1",
"ava": "^6.1.3",
"blurhash": "^2.0.5",
"chalk": "^5.3.0",
"electron": "^30.0.0",
"electron": "^30.0.3",
"lerna": "^8.1.2",
"npm-run-all2": "^6.0.0",
"npm-run-all2": "^6.1.2",
"prettier": "^3.2.5",
"rxjs": "^7.8.1",
"sharp": "^0.33.2",
"typescript": "^5.3.3"
"sharp": "^0.33.3",
"typescript": "^5.4.5"
},
"scripts": {
"artifacts": "lerna run artifacts",
Expand Down
4 changes: 2 additions & 2 deletions packages/binding/__test__/optimize.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ test('should be able to lossless encode webp from jpeg', (t) => {
test('should be able to encode avif from png', (t) => {
t.true(new Transformer(PNG).avifSync({
speed: 10,
threads: 4,
threads: 1,
}).length < PNG.length)
})

test('should be able to encode avif from jpeg', (t) => {
t.true(new Transformer(JPEG).avifSync({
speed: 10,
threads: 4,
threads: 1,
}).length < JPEG.length)
})
13 changes: 6 additions & 7 deletions packages/binding/__test__/transformer.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ test('should be able to encode into webp', async (t) => {
})

test('should be able to decode from avif', async (t) => {
if (process.env.NAPI_RS_FORCE_WASI) {
t.pass()
return
}
const decoder = new Transformer(PNG)
const AVIF = await decoder.avif()
const AVIF = await decoder.avif({
speed: 10,
threads: 1,
})
const avifDecoder = new Transformer(AVIF)
await t.notThrowsAsync(() => avifDecoder.png())
})
Expand All @@ -65,6 +64,6 @@ test('should be able to create transformer from raw rgba pixels', async (t) => {
await t.notThrowsAsync(() => Transformer.fromRgbaPixels(pixels, 32, 32).webp())
})

test('should be able to create transformer from SVG', async (t) => {
await t.notThrowsAsync(() => Transformer.fromSvg(SVG).jpeg())
test('should be able to create transformer from SVG', (t) => {
t.notThrows(() => Transformer.fromSvg(SVG).jpegSync())
})
17 changes: 6 additions & 11 deletions packages/binding/image.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@ import {
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
getDefaultContext as __emnapiGetDefaultContext,
WASI as __WASI,
createOnMessage as __wasmCreateOnMessageForFsProxy,
} from '@napi-rs/wasm-runtime'
import { Volume as __Volume, createFsFromVolume as __createFsFromVolume } from '@napi-rs/wasm-runtime/fs'

import __wasmUrl from './image.wasm32-wasi.wasm?url'

const __fs = __createFsFromVolume(
__Volume.fromJSON({
'/': null,
}),
)

const __wasi = new __WASI({
version: 'preview1',
fs: __fs,
})

const __emnapiContext = __emnapiGetDefaultContext()

const __sharedMemory = new WebAssembly.Memory({
initial: 1024,
maximum: 10240,
initial: 4000,
maximum: 65536,
shared: true,
})

Expand All @@ -37,9 +30,11 @@ const {
asyncWorkPoolSize: 4,
wasi: __wasi,
onCreateWorker() {
return new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
type: 'module',
})

return worker
},
overwriteImports(importObject) {
importObject.env = {
Expand Down
22 changes: 16 additions & 6 deletions packages/binding/image.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,41 @@

/* auto-generated by NAPI-RS */

const __nodeFs= require('node:fs')
const __nodeFs = require('node:fs')
const __nodePath = require('node:path')
const { WASI: __nodeWASI } = require('node:wasi')
const { Worker } = require('node:worker_threads')

const {
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
getDefaultContext: __emnapiGetDefaultContext,
createOnMessage: __wasmCreateOnMessageForFsProxy,
} = require('@napi-rs/wasm-runtime')

const __rootDir = __nodePath.parse(process.cwd()).root

const __wasi = new __nodeWASI({
version: 'preview1',
env: process.env,
preopens: {
'/': '/'
[__rootDir]: __rootDir,
}
})

const __emnapiContext = __emnapiGetDefaultContext()

const __sharedMemory = new WebAssembly.Memory({
initial: 1024,
maximum: 10240,
initial: 4000,
maximum: 65536,
shared: true,
})

let __wasmFilePath = __nodePath.join(__dirname, 'image.wasm32-wasi.wasm')
const __wasmDebugFilePath = __nodePath.join(__dirname, 'image.wasm32-wasi.debug.wasm')

if (!__nodeFs.existsSync(__wasmFilePath)) {
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
__wasmFilePath = __wasmDebugFilePath
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
try {
__wasmFilePath = __nodePath.resolve('@napi-rs/image-wasm32-wasi')
} catch {
Expand All @@ -52,10 +58,14 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
})(),
wasi: __wasi,
onCreateWorker() {
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
env: process.env,
execArgv: ['--experimental-wasi-unstable-preview1'],
})
worker.onmessage = ({ data }) => {
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
}
return worker
},
overwriteImports(importObject) {
importObject.env = {
Expand Down
3 changes: 1 addition & 2 deletions packages/binding/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* auto-generated by NAPI-RS */
/* eslint-disable */

export class Transformer {
constructor(input: Buffer)
/** Support CSS3 color, e.g. rgba(255, 255, 255, .8) */
static fromSvg(input: string | Buffer, background?: string | undefined | null): Transformer
static fromSvg(input: string | Uint8Array, background?: string | undefined | null): Transformer
static fromRgbaPixels(input: Uint8Array | Uint8ClampedArray, width: number, height: number): Transformer
metadata(withExif?: boolean | undefined | null, signal?: AbortSignal | undefined | null): Promise<Metadata>
/**
Expand Down

0 comments on commit afc909f

Please sign in to comment.