Skip to content

Commit

Permalink
feat(cli): respect WASI_SDK_PATH env (#1946)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Feb 12, 2024
1 parent f60c465 commit bec6bd6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cli/src/api/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: ')
Expand Down Expand Up @@ -879,4 +904,10 @@ class Builder {
}
return []
}

private setEnvIfNotExists(env: string, value: string) {
if (!process.env[env]) {
this.envs[env] = value
}
}
}

0 comments on commit bec6bd6

Please sign in to comment.