Skip to content

Commit 2c55c22

Browse files
authored
fix(build): use Homebrew clang for wasm32 C build on macOS (#77)
When CC is set (e.g. ccache cc), the wasm32 C/C++ build can use Apple Clang, which does not support wasm32-unknown-unknown, so the datadog-js-zstd WASM build failed. Set CC_wasm32_unknown_unknown and CXX_wasm32_unknown_unknown to Homebrew's clang so crates like zstd-sys always use a wasm32-capable compiler. Add DEVELOPMENT.md with Rust/rustup, macOS LLVM, and yarn setup steps, and move the build/test notes from README into DEVELOPMENT.md.
1 parent 1c0d40b commit 2c55c22

3 files changed

Lines changed: 54 additions & 6 deletions

File tree

DEVELOPMENT.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Development
2+
3+
## Contributing
4+
5+
See [`CONTRIBUTING.md`](CONTRIBUTING.md).
6+
7+
## Development setup
8+
9+
To build `libdatadog-nodejs` locally (for example, to run tests or try out changes), you need Node.js, Yarn, and Rust.
10+
11+
**Rust (required for native and WASM builds)**
12+
13+
The project compiles Rust for both native Node.js addons and WebAssembly. Use [rustup](https://rustup.rs/) (the recommended and supported method):
14+
15+
1. **Install rustup and Rust** (see https://rustup.rs/ for more options):
16+
17+
```bash
18+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
19+
```
20+
21+
2. **Ensure Rust is on `PATH`** — the rustup installer prints the command for your shell; run it or open a new terminal.
22+
23+
3. **Add the WebAssembly target** (required for the full build):
24+
25+
```bash
26+
rustup target add wasm32-unknown-unknown
27+
```
28+
29+
4. **On macOS only** — the WASM build requires LLVM from Homebrew (Apple's Clang has compatibility issues with some crates). Install it before building:
30+
31+
```bash
32+
brew install llvm
33+
```
34+
35+
5. **Install dependencies:**
36+
37+
```bash
38+
yarn install
39+
```
40+
41+
## Building
42+
43+
* `yarn build`: Build the default workspaces in debug mode.
44+
* `yarn build-release`: Build the default workspaces in release mode.
45+
* `yarn build-all`: Build all workspaces in debug mode. This is useful when working on a workspace that is not a default member yet.
46+
47+
## Run tests
48+
49+
* `yarn test`: Run the JavaScript test suite

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,3 @@ Node.js bindings for [libdatadog](https://github.com/DataDog/libdatadog).
66

77
This project is currently meant to be used only by [dd-trace-js](https://github.com/DataDog/dd-trace-js)
88
and installing it directly is not supported at the moment.
9-
10-
## Building
11-
12-
* `yarn build`: Build the default workspaces in debug mode.
13-
* `yarn build-release`: Build the default workspaces in release mode.
14-
* `yarn build-all`: Build all workspaces in debug mode. This is useful when working on a workspace that is not a default member yet.

scripts/build-wasm.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ if (isMacOS) {
3737
// Add LLVM to PATH if not already included
3838
env.PATH = `${llvmBinDir}:${env.PATH}`;
3939
}
40+
41+
// Force C/C++ code (e.g. zstd-sys) to use Homebrew's clang for wasm32. Otherwise a global
42+
// CC (e.g. ccache cc) can point at Apple Clang, which does not support wasm32-unknown-unknown.
43+
env.CC_wasm32_unknown_unknown = `${llvmBinDir}/clang`;
44+
env.CXX_wasm32_unknown_unknown = `${llvmBinDir}/clang++`;
4045
}
4146

4247
childProcess.execSync(

0 commit comments

Comments
 (0)