feat(cli): respect WASI_SDK_PATH env (#1946)

This commit is contained in:
LongYinan 2024-02-13 01:12:08 +08:00 committed by GitHub
parent f60c465950
commit bec6bd67be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -527,6 +527,31 @@ class Builder {
'wasm32-wasi-threads',
)
this.envs.EMNAPI_LINK_DIR = emnapi
const { WASI_SDK_PATH } = process.env
if (WASI_SDK_PATH && existsSync(WASI_SDK_PATH)) {
this.envs.CARGO_TARGET_WASM32_WASI_PREVIEW1_THREADS_LINKER = join(
WASI_SDK_PATH,
'bin',
'wasm-ld',
)
this.setEnvIfNotExists('CC', join(WASI_SDK_PATH, 'bin', 'clang'))
this.setEnvIfNotExists('CXX', join(WASI_SDK_PATH, 'bin', 'clang++'))
this.setEnvIfNotExists('AR', join(WASI_SDK_PATH, 'bin', 'ar'))
this.setEnvIfNotExists('RANLIB', join(WASI_SDK_PATH, 'bin', 'ranlib'))
this.setEnvIfNotExists(
'CFLAGS',
`--target=wasm32-wasi-threads --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -pthread`,
)
this.setEnvIfNotExists(
'CXXFLAGS',
`--target=wasm32-wasi-threads --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -pthread`,
)
this.setEnvIfNotExists(
`LDFLAGS`,
`-fuse-ld=${WASI_SDK_PATH}/bin/wasm-ld --target=wasm32-wasi-threads`,
)
}
}
debug('Set envs: ')
@ -879,4 +904,10 @@ class Builder {
}
return []
}
private setEnvIfNotExists(env: string, value: string) {
if (!process.env[env]) {
this.envs[env] = value
}
}
}