Skip to content

Commit aef4bab

Browse files
committed
fix: enable Mac builds using Homebrew LLVM
Apple's Clang doesn't support the wasm32-unknown-unknown target, causing secp256k1-sys compilation to fail on Mac. This change automatically detects Mac and uses Homebrew's LLVM which has proper WASM support. Changes: - Makefile: Auto-detect Mac and set CC/AR to use Homebrew LLVM - Makefile: Remove trailing slashes from target declarations for compatibility with both old (Mac 3.81) and new (Linux 4.x) Make - package.json: Fix Make target names to match Makefile - scripts/wasm-pack-test.sh: Wrapper script to set correct compiler for wasm-pack tests on Mac - README.md: Update build instructions for Mac This allows Mac users to build with 'npm run build' without Docker, while maintaining full compatibility with Linux CI builds. Tested on Mac (Apple Silicon) Requires: brew install llvm" Ticket: BTC-0
1 parent 8903d43 commit aef4bab

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed

packages/wasm-utxo/Makefile

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ ifdef WASM_PACK_DEV
66
WASM_PACK_FLAGS += --dev
77
endif
88

9+
# Auto-detect Mac and use Homebrew LLVM for WASM compilation
10+
# Apple's Clang doesn't support wasm32-unknown-unknown target
11+
UNAME_S := $(shell uname -s)
12+
13+
ifeq ($(UNAME_S),Darwin)
14+
# Mac detected - check for Homebrew LLVM installation
15+
HOMEBREW_LLVM := $(shell brew --prefix llvm 2>/dev/null)
16+
17+
ifdef HOMEBREW_LLVM
18+
export CC = $(HOMEBREW_LLVM)/bin/clang
19+
export AR = $(HOMEBREW_LLVM)/bin/llvm-ar
20+
$(info Using Homebrew LLVM: $(HOMEBREW_LLVM))
21+
else
22+
$(warning Homebrew LLVM not found. Install with: brew install llvm)
23+
$(warning Continuing with system clang - may fail on Apple Silicon)
24+
endif
25+
endif
26+
927
define WASM_PACK_COMMAND
1028
$(WASM_PACK) build --no-opt --out-dir $(1) $(WASM_PACK_FLAGS) --target $(2)
1129
endef
@@ -34,16 +52,16 @@ define BUILD
3452
$(call SHOW_WASM_SIZE,$(1))
3553
endef
3654

37-
.PHONY: js/wasm/
38-
js/wasm/:
55+
.PHONY: js/wasm
56+
js/wasm:
3957
$(call BUILD,$@,bundler)
4058

41-
.PHONY: dist/esm/js/wasm/
42-
dist/esm/js/wasm/:
59+
.PHONY: dist/esm/js/wasm
60+
dist/esm/js/wasm:
4361
$(call BUILD,$@,bundler)
4462

45-
.PHONY: dist/cjs/js/wasm/
46-
dist/cjs/js/wasm/:
63+
.PHONY: dist/cjs/js/wasm
64+
dist/cjs/js/wasm:
4765
$(call BUILD,$@,nodejs)
4866

4967
.PHONY: lint

packages/wasm-utxo/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,20 @@ This project is under active development.
2424

2525
## Building
2626

27-
If your system has problems with `wasm-pack` (Mac M1), you can use the `Container.mk` Makefile to build the wasm files:
27+
### Mac
28+
29+
Requires Homebrew LLVM (Apple's Clang doesn't support WASM targets):
30+
31+
```bash
32+
brew install llvm
33+
npm run build
34+
```
35+
36+
### Docker (optional)
37+
38+
If you prefer a containerized build environment:
2839

2940
```bash
30-
cd packages/wasm-utxo
3141
make -f Container.mk build-image
3242
make -f Container.mk build-wasm
3343
```

packages/wasm-utxo/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
"test": "npm run test:mocha && npm run test:wasm-pack && npm run test:imports",
3737
"test:mocha": "mocha --recursive test",
3838
"test:wasm-pack": "npm run test:wasm-pack-node && npm run test:wasm-pack-chrome",
39-
"test:wasm-pack-node": "wasm-pack test --node",
40-
"test:wasm-pack-chrome": "wasm-pack test --headless --chrome",
39+
"test:wasm-pack-node": "./scripts/wasm-pack-test.sh --node",
40+
"test:wasm-pack-chrome": "./scripts/wasm-pack-test.sh --headless --chrome",
4141
"test:esm-import": "node --experimental-wasm-modules bundler-test/test-esm-import.mjs",
4242
"test:cjs-import": "node bundler-test/test-cjs-import.cjs",
4343
"test:imports": "npm run test:esm-import && npm run test:cjs-import",
44-
"build:wasm": "make js/wasm/ && make dist/esm/js/wasm/ && make dist/cjs/js/wasm/",
44+
"build:wasm": "make js/wasm && make dist/esm/js/wasm && make dist/cjs/js/wasm",
4545
"build:ts-esm": "tsc",
4646
"build:ts-cjs": "tsc --project tsconfig.cjs.json",
4747
"build:ts": "npm run build:ts-esm && npm run build:ts-cjs",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# Wrapper script for wasm-pack test that sets correct compiler on Mac
3+
4+
# Detect Mac and set LLVM compiler
5+
if [[ "$(uname -s)" == "Darwin" ]]; then
6+
LLVM_PATH=$(brew --prefix llvm 2>/dev/null)
7+
if [ -n "$LLVM_PATH" ]; then
8+
export CC="$LLVM_PATH/bin/clang"
9+
export AR="$LLVM_PATH/bin/llvm-ar"
10+
fi
11+
fi
12+
13+
# Run wasm-pack test with all passed arguments
14+
wasm-pack test "$@"
15+

0 commit comments

Comments
 (0)