Merge pull request #1095 from napi-rs/cc-wrapper-arg

fix(cli): use shell file path instead of commands for zig CC and CXX
This commit is contained in:
LongYinan 2022-03-13 21:10:15 +08:00 committed by GitHub
commit 77a88cb44a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 1404 additions and 1280 deletions

View file

@ -55,8 +55,8 @@ jobs:
options: -v ${{ github.workspace }}:/napi-rs -w /napi-rs
run: |
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-gcc
yarn --cwd ./examples/napi-compat-mode build --target aarch64-unknown-linux-musl
yarn --cwd ./examples/napi build --target aarch64-unknown-linux-musl
yarn workspace compat-mode-examples build --target aarch64-unknown-linux-musl
yarn workspace examples build --target aarch64-unknown-linux-musl
- name: Setup and run tests
uses: docker://multiarch/alpine:aarch64-latest-stable

View file

@ -22,11 +22,12 @@ jobs:
with:
node-version: 16
check-latest: true
architecture: 'x86'
architecture: 'x64'
cache: 'yarn'
- name: 'Install dependencies'
run: yarn install --mode=skip-build --immutable --network-timeout 300000
run: |
yarn install --mode=skip-build --immutable
- name: 'Build TypeScript'
run: yarn build
@ -37,14 +38,7 @@ jobs:
toolchain: stable
profile: minimal
override: true
- name: Install i686 toolchain
run: rustup target add i686-pc-windows-msvc
- name: Generate Cargo.lock
uses: actions-rs/cargo@v1
with:
command: generate-lockfile
target: i686-pc-windows-msvc
- name: Cache cargo registry
uses: actions/cache@v2
@ -64,10 +58,17 @@ jobs:
command: check
args: --all --bins --examples --tests --target i686-pc-windows-msvc -vvv
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
check-latest: true
architecture: 'x86'
- name: Build Tests
run: |
yarn --cwd ./examples/napi-compat-mode build-i686 --release
yarn --cwd ./examples/napi build-i686 --release
yarn workspace compat-mode-examples build-i686 --release
yarn workspace examples build-i686 --release
yarn test --verbose
env:
RUST_BACKTRACE: 1

View file

@ -57,8 +57,8 @@ jobs:
run: yarn build
- name: Cross build native tests
run: |
yarn --cwd ./examples/napi-compat-mode build --target ${{ matrix.target }} --zig
yarn --cwd ./examples/napi build --target ${{ matrix.target }} --zig
yarn workspace compat-mode-examples build --target ${{ matrix.target }} --zig
yarn workspace examples build --target ${{ matrix.target }} --zig
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:

File diff suppressed because one or more lines are too long

785
.yarn/releases/yarn-3.2.0.cjs vendored Executable file

File diff suppressed because one or more lines are too long

View file

@ -1,3 +1,3 @@
yarnPath: .yarn/releases/yarn-3.1.1.cjs
nodeLinker: node-modules
npmRegistryServer: https://registry.npmjs.org
yarnPath: .yarn/releases/yarn-3.2.0.cjs

View file

@ -41,16 +41,16 @@
},
"devDependencies": {
"@octokit/rest": "^18.12.0",
"@types/inquirer": "^8.1.3",
"@types/inquirer": "^8.2.0",
"@types/js-yaml": "^4.0.5",
"@types/lodash-es": "^4.17.5",
"@types/lodash-es": "^4.17.6",
"clipanion": "^3.1.0",
"colorette": "^2.0.16",
"core-js": "^3.21.0",
"core-js": "^3.21.1",
"debug": "^4.3.3",
"env-paths": "^3.0.0",
"fdir": "^5.2.0",
"inquirer": "^8.2.0",
"inquirer": "^8.2.1",
"js-yaml": "^4.1.0",
"lodash-es": "4.17.21",
"toml": "^3.0.0",

View file

@ -242,9 +242,18 @@ export class BuildCommand extends Command {
throw new Error(`${triple.raw} can not be cross compiled by zig`)
}
const paths = envPaths('napi-rs')
const shellFileExt = process.platform === 'win32' ? 'bat' : 'sh'
const linkerWrapperShell = join(
paths.cache,
`zig-cc-${triple.raw}.${process.platform === 'win32' ? 'bat' : 'sh'}`,
`zig-linker-${triple.raw}.${shellFileExt}`,
)
const CCWrapperShell = join(
paths.cache,
`zig-cc-${triple.raw}.${shellFileExt}`,
)
const CXXWrapperShell = join(
paths.cache,
`zig-cxx-${triple.raw}.${shellFileExt}`,
)
const linkerWrapper = join(paths.cache, `zig-cc-${triple.raw}.js`)
mkdirSync(paths.cache, { recursive: true })
@ -256,6 +265,20 @@ export class BuildCommand extends Command {
mode: '777',
},
)
await writeFileAsync(
CCWrapperShell,
`#!/bin/sh\nzig cc -target ${zigTarget} ${forwardArgs}`,
{
mode: '777',
},
)
await writeFileAsync(
CXXWrapperShell,
`#!/bin/sh\nzig c++ -target ${zigTarget} ${forwardArgs}`,
{
mode: '777',
},
)
await writeFileAsync(
linkerWrapper,
`#!/usr/bin/env node\nconst{writeFileSync} = require('fs')\n${processZigLinkerArgs.toString()}\nconst {status} = require('child_process').spawnSync('zig', ['${
@ -272,10 +295,10 @@ export class BuildCommand extends Command {
)
const envTarget = triple.raw.replaceAll('-', '_').toUpperCase()
Object.assign(additionalEnv, {
CC: `zig cc -target ${zigTarget}`,
CXX: `zig c++ -target ${zigTarget}`,
TARGET_CC: `zig cc -target ${zigTarget}`,
TARGET_CXX: `zig c++ -target ${zigTarget}`,
CC: CCWrapperShell,
CXX: CXXWrapperShell,
TARGET_CC: CCWrapperShell,
TARGET_CXX: CXXWrapperShell,
})
additionalEnv[`CARGO_TARGET_${envTarget}_LINKER`] = linkerWrapperShell
}

View file

@ -133,7 +133,6 @@ test('testDeleteProperty', (t) => {
t.true(bindings.testDeleteProperty(obj, 'k4'))
t.true(bindings.testDeleteProperty(obj, '__NOT_EXISTED__'))
t.true(bindings.testDeleteProperty(obj, k1))
// @ts-expect-error
t.deepEqual(obj, { [k3]: 'k3' })
})
@ -157,7 +156,6 @@ test('testDeleteNamedProperty', (t) => {
t.true(bindings.testDeleteNamedProperty(obj, 'k4'))
t.true(bindings.testDeleteNamedProperty(obj, '__NOT_EXISTED__'))
t.true(bindings.testDeleteNamedProperty(obj, k1))
// @ts-expect-error
t.deepEqual(obj, { [k3]: 'k3' })
})

View file

@ -13,7 +13,7 @@
"build-release": "node ../../cli/scripts/index.js build --js false --release"
},
"dependencies": {
"@types/lodash": "^4.14.178",
"@types/lodash": "^4.14.179",
"lodash": "^4.17.21"
}
}

View file

@ -1,4 +1,5 @@
#![allow(dead_code)]
#![allow(unreachable_code)]
#[macro_use]
extern crate napi_derive;

View file

@ -12,6 +12,6 @@
"table": "^6.8.0"
},
"devDependencies": {
"@types/dockerode": "^3.3.1"
"@types/dockerode": "^3.3.3"
}
}

View file

@ -70,39 +70,39 @@
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-commonjs": "^21.0.2",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-replace": "^3.0.1",
"@rollup/plugin-replace": "^4.0.0",
"@taplo/cli": "^0.3.2",
"@types/debug": "^4.1.7",
"@types/lodash-es": "^4.17.5",
"@types/node": "^17.0.10",
"@types/sinon": "^10.0.8",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"ava": "^4.0.1",
"@types/lodash-es": "^4.17.6",
"@types/node": "^17.0.21",
"@types/sinon": "^10.0.11",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"ava": "^4.1.0",
"benny": "^3.7.1",
"c8": "^7.11.0",
"colorette": "^2.0.16",
"cross-env": "^7.0.3",
"esbuild": "^0.14.13",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"esbuild": "^0.14.25",
"eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"lerna": "^4.0.0",
"lint-staged": "^12.3.1",
"lint-staged": "^12.3.5",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"rollup": "^2.66.0",
"rollup": "^2.70.0",
"shx": "^0.3.4",
"sinon": "^12.0.1",
"sinon": "^13.0.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.4.0",
"ts-node": "^10.7.0",
"tslib": "^2.3.1",
"typescript": "^4.5.5"
"typescript": "^4.6.2"
},
"packageManager": "yarn@3.1.1"
"packageManager": "yarn@3.2.0"
}

1012
yarn.lock

File diff suppressed because it is too large Load diff