Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions packages/wasm-utxo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ ifdef WASM_PACK_DEV
WASM_PACK_FLAGS += --dev
endif

# Auto-detect Mac and use Homebrew LLVM for WASM compilation
# Apple's Clang doesn't support wasm32-unknown-unknown target
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Darwin)
# Mac detected - check for Homebrew LLVM installation
HOMEBREW_LLVM := $(shell brew --prefix llvm 2>/dev/null)

ifdef HOMEBREW_LLVM
export CC = $(HOMEBREW_LLVM)/bin/clang
export AR = $(HOMEBREW_LLVM)/bin/llvm-ar
$(info Using Homebrew LLVM: $(HOMEBREW_LLVM))
else
$(warning Homebrew LLVM not found. Install with: brew install llvm)
$(warning Continuing with system clang - may fail on Apple Silicon)
endif
endif

define WASM_PACK_COMMAND
$(WASM_PACK) build --no-opt --out-dir $(1) $(WASM_PACK_FLAGS) --target $(2)
endef
Expand Down Expand Up @@ -34,16 +52,16 @@ define BUILD
$(call SHOW_WASM_SIZE,$(1))
endef

.PHONY: js/wasm/
js/wasm/:
.PHONY: js/wasm
js/wasm:
$(call BUILD,$@,bundler)

.PHONY: dist/esm/js/wasm/
dist/esm/js/wasm/:
.PHONY: dist/esm/js/wasm
dist/esm/js/wasm:
$(call BUILD,$@,bundler)

.PHONY: dist/cjs/js/wasm/
dist/cjs/js/wasm/:
.PHONY: dist/cjs/js/wasm
dist/cjs/js/wasm:
$(call BUILD,$@,nodejs)

.PHONY: lint
Expand Down
14 changes: 12 additions & 2 deletions packages/wasm-utxo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@ This project is under active development.

## Building

If your system has problems with `wasm-pack` (Mac M1), you can use the `Container.mk` Makefile to build the wasm files:
### Mac

Requires Homebrew LLVM (Apple's Clang doesn't support WASM targets):

```bash
brew install llvm
npm run build
```

### Docker (optional)

If you prefer a containerized build environment:

```bash
cd packages/wasm-utxo
make -f Container.mk build-image
make -f Container.mk build-wasm
```
6 changes: 3 additions & 3 deletions packages/wasm-utxo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
"test": "npm run test:mocha && npm run test:wasm-pack && npm run test:imports",
"test:mocha": "mocha --recursive test",
"test:wasm-pack": "npm run test:wasm-pack-node && npm run test:wasm-pack-chrome",
"test:wasm-pack-node": "wasm-pack test --node",
"test:wasm-pack-chrome": "wasm-pack test --headless --chrome",
"test:wasm-pack-node": "./scripts/wasm-pack-test.sh --node",
"test:wasm-pack-chrome": "./scripts/wasm-pack-test.sh --headless --chrome",
"test:esm-import": "node --experimental-wasm-modules bundler-test/test-esm-import.mjs",
"test:cjs-import": "node bundler-test/test-cjs-import.cjs",
"test:imports": "npm run test:esm-import && npm run test:cjs-import",
"build:wasm": "make js/wasm/ && make dist/esm/js/wasm/ && make dist/cjs/js/wasm/",
"build:wasm": "make js/wasm && make dist/esm/js/wasm && make dist/cjs/js/wasm",
"build:ts-esm": "tsc",
"build:ts-cjs": "tsc --project tsconfig.cjs.json",
"build:ts": "npm run build:ts-esm && npm run build:ts-cjs",
Expand Down
15 changes: 15 additions & 0 deletions packages/wasm-utxo/scripts/wasm-pack-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# Wrapper script for wasm-pack test that sets correct compiler on Mac

# Detect Mac and set LLVM compiler
if [[ "$(uname -s)" == "Darwin" ]]; then
LLVM_PATH=$(brew --prefix llvm 2>/dev/null)
if [ -n "$LLVM_PATH" ]; then
export CC="$LLVM_PATH/bin/clang"
export AR="$LLVM_PATH/bin/llvm-ar"
fi
fi

# Run wasm-pack test with all passed arguments
wasm-pack test "$@"