|
| 1 | +# macOS Build Workarounds for Scrypto |
| 2 | + |
| 3 | +## Problem |
| 4 | + |
| 5 | +The build fails because `blst` (a cryptographic library) requires a C compiler that can target WebAssembly, but Apple's clang doesn't support WASM targets by default. |
| 6 | + |
| 7 | +## Solution Options (Ranked by Reliability) |
| 8 | + |
| 9 | +### Option 1: Use Docker Scrypto Builder (RECOMMENDED) ✅ |
| 10 | + |
| 11 | +This is the **official recommended approach** by Radix for consistent builds. |
| 12 | + |
| 13 | +#### Prerequisites |
| 14 | +- Docker installed and running |
| 15 | + |
| 16 | +#### Steps |
| 17 | + |
| 18 | +1. **Pull the Scrypto Builder Docker image** (version should match your Scrypto version 1.3.0): |
| 19 | + ```bash |
| 20 | + DOCKER_DEFAULT_PLATFORM=linux/amd64 docker pull radixdlt/scrypto-builder:v1.3.0 |
| 21 | + ``` |
| 22 | + |
| 23 | +2. **Build using Docker**: |
| 24 | + ```bash |
| 25 | + cd /Volumes/Storage/OASIS_CLEAN/Providers/Blockchain/NextGenSoftware.OASIS.API.Providers.RadixOASIS/contracts |
| 26 | + |
| 27 | + DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run \ |
| 28 | + -v "$(pwd):/src" \ |
| 29 | + -w /src \ |
| 30 | + radixdlt/scrypto-builder:v1.3.0 \ |
| 31 | + scrypto build |
| 32 | + ``` |
| 33 | + |
| 34 | +3. **Find the WASM file**: |
| 35 | + The WASM file will be created at: `target/wasm32-unknown-unknown/release/oasis_storage.wasm` |
| 36 | + |
| 37 | +**Pros**: Official method, consistent builds, no macOS-specific issues |
| 38 | +**Cons**: Requires Docker |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +### Option 2: Install WASI SDK (Good Alternative) ⚠️ |
| 43 | + |
| 44 | +Provides a WASM-compatible C compiler toolchain. |
| 45 | + |
| 46 | +#### Steps |
| 47 | + |
| 48 | +1. **Download and Install WASI SDK**: |
| 49 | + ```bash |
| 50 | + # Download WASI SDK |
| 51 | + cd ~/Downloads |
| 52 | + curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-macos.tar.gz |
| 53 | + |
| 54 | + # Extract |
| 55 | + tar -xvf wasi-sdk-20.0-macos.tar.gz |
| 56 | + |
| 57 | + # Move to a permanent location (requires sudo) |
| 58 | + sudo mv wasi-sdk-20.0 /opt/wasi-sdk |
| 59 | + ``` |
| 60 | + |
| 61 | +2. **Set Environment Variables** (add to `~/.zshrc` or `~/.bash_profile`): |
| 62 | + ```bash |
| 63 | + export WASI_SDK_PATH="/opt/wasi-sdk" |
| 64 | + export CC="$WASI_SDK_PATH/bin/clang" |
| 65 | + export CXX="$WASI_SDK_PATH/bin/clang++" |
| 66 | + export AR="$WASI_SDK_PATH/bin/llvm-ar" |
| 67 | + export CFLAGS="--sysroot=$WASI_SDK_PATH/share/wasi-sysroot" |
| 68 | + export CXXFLAGS="--sysroot=$WASI_SDK_PATH/share/wasi-sysroot" |
| 69 | + ``` |
| 70 | + |
| 71 | +3. **Apply changes**: |
| 72 | + ```bash |
| 73 | + source ~/.zshrc # or source ~/.bash_profile |
| 74 | + ``` |
| 75 | + |
| 76 | +4. **Try building again**: |
| 77 | + ```bash |
| 78 | + cd contracts |
| 79 | + scrypto build |
| 80 | + ``` |
| 81 | + |
| 82 | +**Pros**: Local build, no Docker needed |
| 83 | +**Cons**: More setup, may still have compatibility issues |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +### Option 3: Use Emscripten (Alternative) ⚠️ |
| 88 | + |
| 89 | +Another WASM compiler option. |
| 90 | + |
| 91 | +#### Steps |
| 92 | + |
| 93 | +1. **Install Emscripten**: |
| 94 | + ```bash |
| 95 | + # Clone emsdk |
| 96 | + git clone https://github.com/emscripten-core/emsdk.git ~/emsdk |
| 97 | + cd ~/emsdk |
| 98 | + |
| 99 | + # Install latest SDK |
| 100 | + ./emsdk install latest |
| 101 | + ./emsdk activate latest |
| 102 | + |
| 103 | + # Activate in current shell |
| 104 | + source ./emsdk_env.sh |
| 105 | + ``` |
| 106 | + |
| 107 | +2. **Configure build to use Emscripten**: |
| 108 | + ```bash |
| 109 | + export CC=emcc |
| 110 | + export CXX=em++ |
| 111 | + ``` |
| 112 | + |
| 113 | +3. **Try building**: |
| 114 | + ```bash |
| 115 | + cd contracts |
| 116 | + scrypto build |
| 117 | + ``` |
| 118 | + |
| 119 | +**Pros**: Full WASM toolchain |
| 120 | +**Cons**: Large installation, may be overkill |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +### Option 4: Build on Linux (If Available) |
| 125 | + |
| 126 | +If you have access to a Linux machine (physical, VM, or cloud instance): |
| 127 | + |
| 128 | +```bash |
| 129 | +# On Linux machine |
| 130 | +cd contracts |
| 131 | +scrypto build |
| 132 | +``` |
| 133 | + |
| 134 | +Then copy the WASM file back to macOS. |
| 135 | + |
| 136 | +**Pros**: Native build, no workarounds needed |
| 137 | +**Cons**: Requires Linux environment |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | +## Quick Test: Try Docker First |
| 142 | + |
| 143 | +The Docker approach is the most reliable. Let's try it: |
| 144 | + |
| 145 | +```bash |
| 146 | +# Check if Docker is installed |
| 147 | +docker --version |
| 148 | + |
| 149 | +# If Docker is available, try: |
| 150 | +cd /Volumes/Storage/OASIS_CLEAN/Providers/Blockchain/NextGenSoftware.OASIS.API.Providers.RadixOASIS/contracts |
| 151 | + |
| 152 | +# Pull the builder (check version - might be v1.3.0 or different) |
| 153 | +DOCKER_DEFAULT_PLATFORM=linux/amd64 docker pull radixdlt/scrypto-builder:v1.3.0 |
| 154 | + |
| 155 | +# Build |
| 156 | +DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run \ |
| 157 | + -v "$(pwd):/src" \ |
| 158 | + -w /src \ |
| 159 | + radixdlt/scrypto-builder:v1.3.0 \ |
| 160 | + scrypto build |
| 161 | +``` |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +## Verifying the Build |
| 166 | + |
| 167 | +After successful build, verify the WASM file exists: |
| 168 | + |
| 169 | +```bash |
| 170 | +ls -lh target/wasm32-unknown-unknown/release/oasis_storage.wasm |
| 171 | +``` |
| 172 | + |
| 173 | +The file should be several MB in size. |
| 174 | + |
| 175 | +--- |
| 176 | + |
| 177 | +## Next Steps After Successful Build |
| 178 | + |
| 179 | +Once you have the WASM file: |
| 180 | + |
| 181 | +1. **Deploy via Radix Wallet Developer Console**: |
| 182 | + - Go to: https://console.radixdlt.com/deploy-package |
| 183 | + - Connect your wallet |
| 184 | + - Upload the WASM file |
| 185 | + - Get package address |
| 186 | + |
| 187 | +2. **Instantiate Component**: |
| 188 | + - Use package address to instantiate `OasisStorage` component |
| 189 | + - Get component address |
| 190 | + |
| 191 | +3. **Update Configuration**: |
| 192 | + - Update `OASIS_DNA.json` with component address |
| 193 | + |
| 194 | +See `STEP_BY_STEP_WALLET_DEPLOYMENT.md` for full deployment instructions. |
| 195 | + |
| 196 | +--- |
| 197 | + |
| 198 | +## References |
| 199 | + |
| 200 | +- Scrypto Builder: https://docs.radixdlt.com/docs/productionize-your-code |
| 201 | +- WASI SDK: https://github.com/WebAssembly/wasi-sdk |
| 202 | +- Emscripten: https://emscripten.org/docs/getting_started/downloads.html |
| 203 | + |
0 commit comments