fix(cli): zig cross armv7 (#1384)
This commit is contained in:
parent
00b09bca6e
commit
2abc94681e
5 changed files with 36 additions and 23 deletions
3
.github/workflows/linux-aarch64.yaml
vendored
3
.github/workflows/linux-aarch64.yaml
vendored
|
@ -2,7 +2,6 @@ name: Linux-aarch64
|
|||
|
||||
env:
|
||||
DEBUG: 'napi:*'
|
||||
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: 'aarch64-linux-gnu-gcc-9'
|
||||
|
||||
on:
|
||||
push:
|
||||
|
@ -41,7 +40,7 @@ jobs:
|
|||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
key: stable-linux-aarch64-gnu-node@16-cargo-cache
|
||||
key: stable-linux-aarch64-gnu-node@18-cargo-cache
|
||||
|
||||
- name: Install ziglang
|
||||
uses: goto-bus-stop/setup-zig@v2
|
||||
|
|
|
@ -58,12 +58,14 @@ function processZigLinkerArgs(platform: string, args: string[]) {
|
|||
return newArgs
|
||||
}
|
||||
if (platform.includes('linux')) {
|
||||
return args.map((arg) => {
|
||||
if (arg === '-lgcc_s') {
|
||||
return '-lunwind'
|
||||
}
|
||||
return arg
|
||||
})
|
||||
return args
|
||||
.map((arg) => {
|
||||
if (arg === '-lgcc_s') {
|
||||
return '-lunwind'
|
||||
}
|
||||
return arg
|
||||
})
|
||||
.filter((arg) => arg !== '-march=armv7-a')
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
@ -328,10 +330,11 @@ export class BuildCommand extends Command {
|
|||
this.zigABIVersion ?? (isCrossForLinux && triple.abi === 'gnu')
|
||||
? DEFAULT_GLIBC_TARGET
|
||||
: null
|
||||
const zigTarget = `${ZIG_PLATFORM_TARGET_MAP[triple.raw]}${
|
||||
const mappedZigTarget = ZIG_PLATFORM_TARGET_MAP[triple.raw]
|
||||
const zigTarget = `${mappedZigTarget}${
|
||||
zigABIVersion ? `.${zigABIVersion}` : ''
|
||||
}`
|
||||
if (!zigTarget) {
|
||||
if (!mappedZigTarget) {
|
||||
throw new Error(`${triple.raw} can not be cross compiled by zig`)
|
||||
}
|
||||
const paths = envPaths('napi-rs')
|
||||
|
@ -371,14 +374,14 @@ export class BuildCommand extends Command {
|
|||
)
|
||||
await writeFileAsync(
|
||||
CCWrapperShell,
|
||||
`${SHEBANG_SH}zig cc -target ${zigTarget} ${forwardArgs}`,
|
||||
`${SHEBANG_SH}node ${linkerWrapper} cc ${forwardArgs}`,
|
||||
{
|
||||
mode: '777',
|
||||
},
|
||||
)
|
||||
await writeFileAsync(
|
||||
CXXWrapperShell,
|
||||
`${SHEBANG_SH}zig c++ -target ${zigTarget} ${forwardArgs}`,
|
||||
`${SHEBANG_SH}node ${linkerWrapper} c++ ${forwardArgs}`,
|
||||
{
|
||||
mode: '777',
|
||||
},
|
||||
|
@ -386,9 +389,7 @@ export class BuildCommand extends Command {
|
|||
|
||||
await writeFileAsync(
|
||||
linkerWrapper,
|
||||
`${SHEBANG_NODE}const{writeFileSync} = require('fs')\n${processZigLinkerArgs.toString()}\nconst {status} = require('child_process').spawnSync('zig', ['${
|
||||
triple.platform === 'win32' ? 'c++' : 'cc'
|
||||
}', ...processZigLinkerArgs('${
|
||||
`${SHEBANG_NODE}const{writeFileSync} = require('fs')\n${processZigLinkerArgs.toString()}\nconst {status} = require('child_process').spawnSync('zig', [process.argv[2] === "c++" || process.argv[2] === "cc" ? "" : "cc", ...processZigLinkerArgs('${
|
||||
triple.raw
|
||||
}', process.argv.slice(2)), '-target', '${zigTarget}'], { stdio: 'inherit', shell: true })\nwriteFileSync('${linkerWrapper.replaceAll(
|
||||
'\\',
|
||||
|
@ -822,22 +823,23 @@ async function writeJsBinding(
|
|||
|
||||
async function patchArmFeaturesHForArmTargets() {
|
||||
let zigExePath: string
|
||||
let zigLibDir: string | undefined
|
||||
try {
|
||||
const zigEnv = JSON.parse(execSync(`zig env`, { encoding: 'utf8' }).trim())
|
||||
zigExePath = zigEnv['zig_exe']
|
||||
zigLibDir = zigEnv['lib_dir']
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
'Cannot get zig env correctly, please ensure the zig is installed correctly on your system',
|
||||
)
|
||||
}
|
||||
try {
|
||||
await writeFileAsync(
|
||||
join(zigExePath, '../lib/libc/glibc/sysdeps/arm/arm-features.h'),
|
||||
ARM_FEATURES_H,
|
||||
{
|
||||
mode: 0o644,
|
||||
},
|
||||
)
|
||||
const p = zigLibDir
|
||||
? join(zigLibDir, 'libc/glibc/sysdeps/arm/arm-features.h')
|
||||
: join(zigExePath, '../lib/libc/glibc/sysdeps/arm/arm-features.h')
|
||||
await writeFileAsync(p, ARM_FEATURES_H, {
|
||||
mode: 0o644,
|
||||
})
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
`Cannot patch arm-features.h, error: ${
|
||||
|
|
|
@ -8,6 +8,9 @@ version = "0.1.0"
|
|||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[features]
|
||||
snmalloc = ["snmalloc-rs"]
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4"
|
||||
futures = "0.3"
|
||||
|
@ -27,6 +30,11 @@ serde_derive = "1"
|
|||
serde_json = "1"
|
||||
tokio = { version = "1.20.0", features = ["full"] }
|
||||
|
||||
[dependencies.snmalloc-rs]
|
||||
version = "0.3"
|
||||
features = ["build_cc", "local_dynamic_tls"]
|
||||
optional = true
|
||||
|
||||
[build-dependencies]
|
||||
napi-build = { path = "../../crates/build" }
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@ extern crate napi_derive;
|
|||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[cfg(feature = "snmalloc")]
|
||||
#[global_allocator]
|
||||
static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
|
||||
|
||||
#[napi]
|
||||
/// This is a const
|
||||
pub const DEFAULT_COST: u32 = 12;
|
||||
|
|
|
@ -27,5 +27,5 @@
|
|||
"lib": ["dom", "DOM.Iterable", "ES2019", "ES2020", "esnext"]
|
||||
},
|
||||
"include": ["."],
|
||||
"exclude": ["node_modules", "bench", "cli/scripts", "scripts"]
|
||||
"exclude": ["node_modules", "bench", "cli/scripts", "scripts", "target"]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue