interlay / interbtc

interBTC: Bitcoin Anywhere
https://app.interlay.io/
Apache License 2.0
247 stars 83 forks source link

Issue while Compiling Node for macOS #1087

Closed nakul1010 closed 1 year ago

nakul1010 commented 1 year ago

Problem

Compiling the InterBtc repository on macOS requires specific dependencies to be installed correctly. The readme file provides multiple options for obtaining these dependencies. However, it is essential to follow the recommended steps in the correct order, especially for first-time macOS node compilation.

nakul1010 commented 1 year ago

Solution

Follow the steps below to compile the InterBtc node on macOS:

  1. Install Rust

    Execute the following command in the terminal to install Rust:

    curl <https://sh.rustup.rs> -sSf | sh
    
  2. Install OpenSSL

    Install OpenSSL by running the following command:

    brew install openssl
    
  3. Update Current Shell

    Update the current shell by executing the following command:

    source ~/.cargo/env
    
  4. Install Cmake

    brew install cmake
  5. Install Clang via OpenSSL (not brew)

    Install Clang by running the command:

    xcode-select --install
    
  6. Verify Correct Paths

    Ensure that the following paths are correct:

    which llvm-ar
    /opt/homebrew/opt/llvm/bin/llvm-ar
    
    which clang
    /opt/homebrew/opt/llvm/bin/clang
    
  7. Check GCC Version

    Verify that the GCC version is greater than 10:

    gcc --version
    Apple clang version 14.0.0 (clang-1400.0.29.202)
    Target: arm64-apple-darwin22.2.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin
    
  8. Run Cargo Commands and Link LLVM and Clang

    Execute the following commands to build and link LLVM and Clang:

    cargo clean
    
    AR=/opt/homebrew/opt/llvm/bin/llvm-ar CC=/opt/homebrew/opt/llvm/bin/clang cargo build
    

Important Consideration

By following these steps carefully, you should be able to successfully compile the InterBtc node on macOS.

References

nud3l commented 1 year ago

On a new mac, it's also required to install llvm brew install llvm.

baidang201 commented 1 year ago

cargo run --release --bin interbtc-parachain -- --dev report

error: failed to run custom build command for `secp256k1-sys v0.4.2`

  running: "clang" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DUSE_NUM_NONE=1" "-DUSE_FIELD_INV_BUILTIN=1" "-DUSE_SCALAR_INV_BUILTIN=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/Users/bread/Workspace/playground/wasm-pack-test/target/wasm32-unknown-unknown/release/build/secp256k1-sys-923268476155554b/out/depend/secp256k1/contrib/lax_der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c"
  cargo:warning=error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'
  cargo:warning=1 error generated.
  exit status: 1

fixed by

1 Install llvm via homebrew, brew install llvm
2 Add the LLVM to your path PATH="/opt/homebrew/opt/llvm/bin:$PATH" (could be in your profile, .zshrc or equivalent)
3 Ensure you have the AR and CLANG environment vars exported, CC=/opt/homebrew/opt/llvm/bin/clang & AR=/opt/homebrew/opt/llvm/bin/llvm-ar
4 Run your command and hope for the best...

https://substrate.stackexchange.com/questions/1098/how-to-use-sp-core-in-libraries-that-target-wasm-for-the-web