filecoin-project / filecoin-ffi

C and CGO bindings for Filecoin's Rust libraries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

build failure on m1 Mac due to missing toolchain

yusefnapora opened this issue · comments

On an m1 Mac, the nightly-2020-10-05 toolchain can't be found for the aarch64-apple-darwin platform, so the build fails.

Changing rust/rust-toolchain to 1.50.0 makes things start to compile, but it looks like it hits this issue in the sha2-asm crate, since I get output like this:

error: failed to run custom build command for `sha2-asm v0.5.5`

Caused by:
  process didn't exit successfully: `/Users/yusef/work/repos/filecoin-ffi/rust/target/release/build/sha2-asm-cb66c0b7bf3bbc7f/build-script-build` (exit code: 1)
  --- stdout
  TARGET = Some("aarch64-apple-darwin")
  OPT_LEVEL = Some("3")
  HOST = Some("aarch64-apple-darwin")
  CC_aarch64-apple-darwin = None
  CC_aarch64_apple_darwin = None
  HOST_CC = None
  CC = None
  CFLAGS_aarch64-apple-darwin = None
  CFLAGS_aarch64_apple_darwin = None
  HOST_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = None
  running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-Wall" "-Wextra" "-march=armv8-a+crypto" "-c" "-o" "/Users/yusef/work/repos/filecoin-ffi/rust/target/release/build/sha2-asm-e5881292d436fa64/out/src/sha256_aarch64.o" "-c" "src/sha256_aarch64.S"
  cargo:warning=src/sha256_aarch64.S:64:2: error: ADR/ADRP relocations must be GOT relative
  cargo:warning= adrp x2, .K
  cargo:warning= ^
  cargo:warning=src/sha256_aarch64.S:64:2: error: unknown AArch64 fixup kind!
  cargo:warning= adrp x2, .K
  cargo:warning= ^
  cargo:warning=src/sha256_aarch64.S:65:2: error: unknown AArch64 fixup kind!
  cargo:warning= add x2, x2, :lo12:.K
  cargo:warning= ^
  exit code: 1

  --- stderr

I think that sha2-asm is pulled in by rust-fil-proofs, but that's as far as I have time to dig atm :)

To save you some time:

sha2-asm is a dependency of shaw2raw in rust-fil-proofs

sw_vers

ProductName:	macOS
ProductVersion:	11.3.1
BuildVersion:	20E241

go version

go version go1.16.3 darwin/arm64

Dockerfile:

FROM golang:1.15.6 as builder
RUN apt-get update && apt-get install -y ca-certificates make gcc musl-dev git mesa-opencl-icd ocl-icd-opencl-dev bzr jq pkg-config curl clang build-essential hwloc libhwloc-dev tmux

####### rust for filcrypto
ENV RUSTUP_HOME=/rust
ENV CARGO_HOME=/cargo
ENV PATH=/cargo/bin:/rust/bin:$PATH
RUN echo "(curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly --no-modify-path) && rustup default nightly" > /install-rust.sh && chmod 755 /install-rust.sh
RUN /install-rust.sh
RUN rustup show

####### get lotus source
WORKDIR /app
RUN git clone https://github.com/filecoin-project/lotus.git
WORKDIR /app/lotus
RUN git checkout v1.8.0

####### filcrypto on Mac M1
RUN git submodule update --init --recursive
ENV GOARCH=arm64
ENV CGO_ENABLED=1
ENV LIBRARY_PATH=/opt/homebrew/lib
WORKDIR /app/lotus/extern/filecoin-ffi
RUN git fetch -a
RUN git checkout m1-portable
RUN make clean
RUN make

####### build lotus
WORKDIR /app/lotus
RUN make 2k

Error:

docker build -t lotus .
[+] Building 492.1s (21/28)
 => [internal] load build definition from Dockerfile                   0.0s
 => => transferring dockerfile: 1.55kB                                 0.0s
 => [internal] load .dockerignore                                      0.0s
 => => transferring context: 2B                                        0.0s
 => [internal] load metadata for docker.io/library/golang:1.15.6       2.8s
 => [auth] library/golang:pull token for registry-1.docker.io          0.0s
 => CACHED [ 1/24] FROM docker.io/library/golang:1.15.6@sha256:de97ba  0.0s
 => [ 2/24] RUN apt-get update && apt-get install -y ca-certificates  62.5s
 => [ 3/24] RUN echo "(curl https://sh.rustup.rs -sSf | sh -s -- -y -  0.4s
 => [ 4/24] RUN /install-rust.sh                                      43.5s
 => [ 5/24] RUN rustup show                                            0.3s
 => [ 6/24] WORKDIR /app                                               0.0s
 => [ 7/24] RUN git clone https://github.com/filecoin-project/lotus.  22.1s
 => [ 8/24] WORKDIR /app/lotus                                         0.0s
 => [ 9/24] RUN git checkout v1.8.0                                    0.3s
 => [10/24] RUN git submodule update --init --recursive               16.5s
 => [11/24] WORKDIR /app/lotus/extern/filecoin-ffi                     0.0s
 => [12/24] RUN git fetch -a                                           1.3s
 => [13/24] RUN git checkout m1-portable                               0.2s
 => [14/24] RUN make clean                                             0.3s
 => [15/24] RUN make                                                 264.6s
 => [16/24] WORKDIR /app/lotus                                         0.1s
 => ERROR [17/24] RUN make 2k                                 77.0s

...
#21 37.31 go: downloading github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901
#21 54.04 # github.com/filecoin-project/filecoin-ffi/generated
#21 54.04 /usr/bin/ld: skipping incompatible extern/filecoin-ffi/generated/../libfilcrypto.a when searching for -lfilcrypto
#21 54.04 /usr/bin/ld: skipping incompatible extern/filecoin-ffi/generated/../libfilcrypto.a when searching for -lfilcrypto
#21 54.04 /usr/bin/ld: skipping incompatible extern/filecoin-ffi/generated/../libfilcrypto.a when searching for -lfilcrypto
#21 54.04 /usr/bin/ld: skipping incompatible extern/filecoin-ffi/generated/../libfilcrypto.a when searching for -lfilcrypto
#21 54.04 /usr/bin/ld: skipping incompatible extern/filecoin-ffi/generated/../libfilcrypto.a when searching for -lfilcrypto
#21 54.04 /usr/bin/ld: cannot find -lfilcrypto
#21 54.04 collect2: error: ld returned 1 exit status
#21 76.91 make: *** [Makefile:86: lotus] Error 2

commented

m1 build support has been properly resolved for some time now.