diff --git a/.eslintrc.yml b/.eslintrc.yml index c78e1ab6..1ad66b0b 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -223,7 +223,7 @@ overrides: project: ./bench/tsconfig.json - files: - - ./*.{cjs,js} + - ./*.js plugins: - '@typescript-eslint' parserOptions: diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 25362803..75d77064 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -22,7 +22,8 @@ jobs: - name: Build docker image run: | - docker build . -f Dockerfile.alpine --pull --no-cache -t docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts + docker build . -f alpine.Dockerfile --pull --no-cache -t docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts - name: Push docker image - run: docker push docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts + run: | + docker push docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts diff --git a/.github/workflows/linux-aarch64.yaml b/.github/workflows/linux-aarch64.yaml new file mode 100644 index 00000000..70ebf4dc --- /dev/null +++ b/.github/workflows/linux-aarch64.yaml @@ -0,0 +1,36 @@ +name: Linux-aarch64 + +on: + push: + branches: [master, develop] + pull_request: + +jobs: + build: + name: stable - x86_64-unknown-linux-musl - node@14 + runs-on: ubuntu-latest + + steps: + - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset + - uses: actions/checkout@v2 + + - name: 'Setup and run tests' + uses: docker://multiarch/ubuntu-core:arm64-focal + with: + args: > + sh -c " + apt-get update && \ + apt-get install -y ca-certificates gnupg2 llvm clang curl && \ + curl -sL https://deb.nodesource.com/setup_14.x | bash - && \ + apt-get install -y nodejs && \ + curl https://sh.rustup.rs -sSf --output rustup.sh && \ + sh rustup.sh -y --profile minimal --default-toolchain stable && \ + . $HOME/.cargo/env && \ + npm install -g yarn && \ + yarn --ignore-optional && \ + yarn build && \ + cargo check -vvv && \ + cargo test -p napi-sys --lib -- --nocapture && \ + yarn build:test && \ + yarn test + " diff --git a/.github/workflows/linux-musl.yaml b/.github/workflows/linux-musl.yaml index c4ee0231..bda32b76 100644 --- a/.github/workflows/linux-musl.yaml +++ b/.github/workflows/linux-musl.yaml @@ -1,4 +1,4 @@ -name: Musl +name: Linux musl on: push: @@ -7,11 +7,7 @@ on: jobs: build: - name: stable - x86_64-unknown-linux-musl - node@${{ matrix.node }} - strategy: - fail-fast: false - matrix: - node: ['10', '12', '14'] + name: stable - x86_64-unknown-linux-musl - node@14 runs-on: ubuntu-latest steps: @@ -49,6 +45,6 @@ jobs: - name: Unit test run: | - docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder sh -c "yarn --cwd ./test_module build && yarn test" + docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder sh -c "yarn build:test && yarn test" env: RUST_BACKTRACE: 1 diff --git a/.github/workflows/napi3.yaml b/.github/workflows/napi3.yaml index b7e5924b..ac47eb6a 100644 --- a/.github/workflows/napi3.yaml +++ b/.github/workflows/napi3.yaml @@ -1,4 +1,4 @@ -name: Linux-N-API-3 +name: Linux N-API@3 on: push: @@ -73,11 +73,6 @@ jobs: command: test args: -p napi-sys --lib -- --nocapture - - name: Write ava.config.js for ava@2 - run: | - node write-ava-config.js - cat ava.config.js - - name: Unit tests run: | yarn --cwd ./test_module --ignore-engines build diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 154a8e1c..b331cab6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,4 +1,4 @@ -name: Test +name: macOS/Windows/Linux x64 on: push: diff --git a/.npmignore b/.npmignore index 78a90533..40f96895 100644 --- a/.npmignore +++ b/.npmignore @@ -13,5 +13,6 @@ rustfmt.toml .eslintignore .eslintrc.yml Cargo.toml -Dockerfile.alpine +alpine.Dockerfile +arm64v8.Dockerfile yarn.lock diff --git a/Dockerfile.alpine b/alpine.Dockerfile similarity index 100% rename from Dockerfile.alpine rename to alpine.Dockerfile diff --git a/ava.config.cjs b/ava.config.js similarity index 63% rename from ava.config.cjs rename to ava.config.js index b5b82e40..707a29db 100644 --- a/ava.config.cjs +++ b/ava.config.js @@ -1,18 +1,15 @@ const configuration = { extensions: ['ts', 'tsx'], files: ['test_module/__test__/**/*.spec.ts'], - require: [ - require('os').platform() === 'freebsd' - ? 'ts-node/register/transpile-only' - : '@swc-node/register', - ], + require: ['ts-node/register/transpile-only'], environmentVariables: { TS_NODE_PROJECT: './test_module/tsconfig.json', }, + timeout: '1m', } if (parseInt(process.versions.napi, 10) < 4) { configuration.compileEnhancements = false } -module.exports = configuration +export default configuration diff --git a/napi/src/env.rs b/napi/src/env.rs index 7ca8bc07..498f3689 100644 --- a/napi/src/env.rs +++ b/napi/src/env.rs @@ -146,19 +146,19 @@ impl Env { } pub fn create_string(&self, s: &str) -> Result { - self.create_string_from_chars(s.as_ptr() as *const _, s.len() as u64) + self.create_string_from_chars(s.as_ptr() as *const c_char, s.len() as u64) } pub fn create_string_from_std(&self, s: String) -> Result { - self.create_string_from_chars(s.as_ptr() as *const _, s.len() as u64) + self.create_string_from_chars(s.as_ptr() as *const c_char, s.len() as u64) } pub fn create_string_from_vec_u8(&self, bytes: Vec) -> Result { - self.create_string_from_chars(bytes.as_ptr() as *const _, bytes.len() as u64) + self.create_string_from_chars(bytes.as_ptr() as *const c_char, bytes.len() as u64) } pub fn create_string_from_vec_i8(&self, bytes: Vec) -> Result { - self.create_string_from_chars(bytes.as_ptr(), bytes.len() as u64) + self.create_string_from_chars(bytes.as_ptr() as *const c_char, bytes.len() as u64) } fn create_string_from_chars(&self, data_ptr: *const c_char, len: u64) -> Result { diff --git a/package.json b/package.json index 45d19928..c7c4ccd1 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ ], "license": "MIT", "scripts": { - "bench": "cross-env SWC_NODE_PROJECT='./bench/tsconfig.json' node -r @swc-node/register bench/bench.ts", + "bench": "cross-env SWC_NODE_PROJECT='./bench/tsconfig.json' node -r ts-node/register/transpile-only bench/bench.ts", "build": "tsc -p tsconfig.json && chmod 777 scripts/index.js", "build:bench": "yarn --cwd ./bench build", "build:test": "yarn --cwd ./test_module build", @@ -72,7 +72,6 @@ }, "devDependencies": { "@istanbuljs/nyc-config-typescript": "^1.0.1", - "@swc-node/register": "^1.0.0", "@types/debug": "^4.1.5", "@types/inquirer": "^7.3.1", "@types/lodash": "^4.14.162", diff --git a/tsconfig.root-lint.json b/tsconfig.root-lint.json index a4f467cf..ee261b54 100644 --- a/tsconfig.root-lint.json +++ b/tsconfig.root-lint.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig.json", - "files": ["./ava.config.cjs", "./write-ava-config.js"] + "files": ["./ava.config.js"] } diff --git a/write-ava-config.js b/write-ava-config.js deleted file mode 100644 index 01842d84..00000000 --- a/write-ava-config.js +++ /dev/null @@ -1,10 +0,0 @@ -const { writeFileSync } = require('fs') -const { join } = require('path') - -const config = require('./ava.config.cjs') - -const code = ` -export default ${JSON.stringify(config, null, 2)} -` - -writeFileSync(join(__dirname, 'ava.config.js'), code) diff --git a/yarn.lock b/yarn.lock index fa7b00b8..d83682ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -256,13 +256,6 @@ resolved "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.2.tgz#26520bf09abe4a5644cd5414e37125a8954241dd" integrity sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw== -"@node-rs/helper@^0.4.0": - version "0.4.0" - resolved "https://registry.npmjs.org/@node-rs/helper/-/helper-0.4.0.tgz#deec7d95aafa90535980a51cbd5336b8bbefe93a" - integrity sha512-fSyHEXmlt/FueKqAYiGFCnkohnQBMQwUr6VYPeZEeVBAzQzhioS1WaRe2fSpOuRKIimCQEvxhQ6fwsYxYakfGA== - dependencies: - tslib "^2.0.1" - "@nodelib/fs.scandir@2.1.3": version "2.1.3" resolved "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz#3a582bdb53804c6ba6d146579c46e52130cf4a3b" @@ -459,57 +452,6 @@ resolved "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz#8da5c6530915653f3a1f38fd5f101d8c3f8079c5" integrity sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ== -"@swc-node/core@^1.0.0": - version "1.0.0" - resolved "https://registry.npmjs.org/@swc-node/core/-/core-1.0.0.tgz#d719abe9d5aa49bb169153d1f3b8ef5364f6f30d" - integrity sha512-U0ebtvZVAVjvIjIw2NW07siJFszoOniE5DX1XB08RRvrV1hSI/yuTT81z1onoI66Fhc1l+AJbZLq4U19VEBCOA== - dependencies: - "@swc/core" "^1.2.34" - -"@swc-node/register@^1.0.0": - version "1.0.0" - resolved "https://registry.npmjs.org/@swc-node/register/-/register-1.0.0.tgz#c7bee0feea44b08c765b6745f928e7ed2f670511" - integrity sha512-pUz5KvJjg+cNlwTeqW4FOQ1nwWsqbFMifysKPEseBCiW/QKd/NhufYPdqkAa8uvMBEcxEtFsH7mnFT/es5AbCg== - dependencies: - "@swc-node/core" "^1.0.0" - "@swc-node/sourcemap-support" "^0.1.8" - chalk "^4.1.0" - debug "^4.2.0" - pirates "^4.0.1" - -"@swc-node/sourcemap-support@^0.1.8": - version "0.1.8" - resolved "https://registry.npmjs.org/@swc-node/sourcemap-support/-/sourcemap-support-0.1.8.tgz#8cf74175ae5e3374612011e7e75c03637019db4c" - integrity sha512-AOH32yNN8UJh6Ayc+r3mnPdrjqqEjtXr9wsEiEhh3OqJWFXqkMOHC+18FYhHdTzGzhaYqUshQONjqOTC38yx7Q== - dependencies: - source-map-support "^0.5.19" - -"@swc/core-darwin@^1.2.34": - version "1.2.34" - resolved "https://registry.npmjs.org/@swc/core-darwin/-/core-darwin-1.2.34.tgz#dd69b1a12b7a2cb9e43a5e8a78a8d2d7ff392f53" - integrity sha512-OKOHOcqBgvBQiGC7doCa4CXKVDpO1QMIQogCFelqs82YbcQa6YEWvB6+ujiw1oUWaXP2fed1TFHDpHFJWorxIQ== - -"@swc/core-linux@^1.2.34": - version "1.2.34" - resolved "https://registry.npmjs.org/@swc/core-linux/-/core-linux-1.2.34.tgz#927fbdbfed1e842bbda4dc96d1407c5a0e67234d" - integrity sha512-85ryQe9M4xPY9R4mRfbU/Gk/z45GVPG1LiJhf99jA+7RmNiffwJXLRuD8SwkE5rKHO8My1mVCha8uBQnZIDhEg== - -"@swc/core-win32@^1.2.34": - version "1.2.34" - resolved "https://registry.npmjs.org/@swc/core-win32/-/core-win32-1.2.34.tgz#2eeba70a72bb71acf4efcfab099d4cb96826b587" - integrity sha512-DxxKEo9Q/jOGTXizPJXdKkfSjGU3cU4df9ZY7nslWVp0c7r+hnHcplh2A1CklOdLinUTBUP+3DHtLTyhLElPBg== - -"@swc/core@^1.2.34": - version "1.2.34" - resolved "https://registry.npmjs.org/@swc/core/-/core-1.2.34.tgz#bd1d64d219cf116667517aadd7eb804045743d7c" - integrity sha512-V0qMusSNpKUwkjN42zfeEEILldnAx+XFVH7q96ofrM/MRYDWjYZJU9eaCwAGNb/bLS7+UWq8e/nxxpOvKLnjdQ== - dependencies: - "@node-rs/helper" "^0.4.0" - optionalDependencies: - "@swc/core-darwin" "^1.2.34" - "@swc/core-linux" "^1.2.34" - "@swc/core-win32" "^1.2.34" - "@szmarczak/http-timer@^1.1.2": version "1.1.2" resolved "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz#b1665e2c461a2cd92f4c1bbf50d5454de0d4b421" @@ -2849,11 +2791,6 @@ node-fetch@^2.6.1: resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== -node-modules-regexp@^1.0.0: - version "1.0.0" - resolved "https://registry.npmjs.org/node-modules-regexp/-/node-modules-regexp-1.0.0.tgz#8d9dbe28964a4ac5712e9131642107c71e90ec40" - integrity sha1-jZ2+KJZKSsVxLpExZCEHxx6Q7EA= - node-preload@^0.2.1: version "0.2.1" resolved "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz#c03043bb327f417a18fee7ab7ee57b408a144301" @@ -3264,13 +3201,6 @@ pify@^4.0.1: resolved "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231" integrity sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g== -pirates@^4.0.1: - version "4.0.1" - resolved "https://registry.npmjs.org/pirates/-/pirates-4.0.1.tgz#643a92caf894566f91b2b986d2c66950a8e2fb87" - integrity sha512-WuNqLTbMI3tmfef2TKxlQmAiLHKtFhlsCZnPIpuv2Ow0RDVO8lfy1Opf4NUzlMXLjPl+Men7AuVdX6TA+s+uGA== - dependencies: - node-modules-regexp "^1.0.0" - pkg-conf@^3.1.0: version "3.1.0" resolved "https://registry.npmjs.org/pkg-conf/-/pkg-conf-3.1.0.tgz#d9f9c75ea1bae0e77938cde045b276dac7cc69ae" @@ -4020,7 +3950,7 @@ tslib@^1.8.1, tslib@^1.9.0: resolved "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043" integrity sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q== -tslib@^2.0.1, tslib@^2.0.3: +tslib@^2.0.3: version "2.0.3" resolved "https://registry.npmjs.org/tslib/-/tslib-2.0.3.tgz#8e0741ac45fc0c226e58a17bfc3e64b9bc6ca61c" integrity sha512-uZtkfKblCEQtZKBF6EBXVZeQNl82yqtDQdv+eck8u7tdPxjLu2/lp5/uPW+um2tpuxINHWy3GhiccY7QgEaVHQ==