Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: build filecoin-ffi on arm based OS #278

Closed
wants to merge 14 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,4 @@ commands:
- save_cache:
key: v28-proof-params-{{ arch }}
paths:
- "~/filecoin-proof-parameters/"
- "~/filecoin-proof-parameters/"
Binary file added builder/.DS_Store
Binary file not shown.
Binary file added builder/arm64/.DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions builder/arm64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#FROM --platform=arm64 golang@sha256:96e888160bd68f54a1165b23c66318aea4ff6a4726cb854276d6d776c14b8978
FROM ubuntu:latest as builder
#FROM rust:slim-buster@sha256:5b0c5f6cd5aa84f6dd3f2188ac84aa0e0d602b514ccc14e9d1ebd5b865aa7849
#FROM golang:1.17.9-stretch

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y wget jq hwloc ocl-icd-opencl-dev git libhwloc-dev pkg-config make curl && \
apt-get install -y cargo golang-go

WORKDIR /filecoin-ffi/

#RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup +nightly target add aarch64-unknown-linux-gnu
RUN cargo --help
RUN git clone https://github.com/filecoin-project/filecoin-ffi.git . && \
RUSTFLAGS="-C target-cpu=native -g" FFI_BUILD_FROM_SOURCE=1 make
27 changes: 27 additions & 0 deletions builder/arm64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# filecoin-ffi build workaround

As of this writing, .circleci does not support arm based images and as a workaround we need to try and build the filecoin-ffi in a containerized environment. The workaround is to create a docker image using an ARM64 based operating system and build the binaries in the image. We can then pull (`cp`) the binaries to the host.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what "arm based images" are, but CircleCI has ARM64 support, which is e.g. be used by rust-fil-proofs: https://github.com/filecoin-project/rust-fil-proofs/blob/6260c2a5409bda6c2514e8c355d52623939f4bc7/.circleci/config.yml#L19-L22

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Thank you for this. I'll experiment with this image then.

I saw this note on circle ci.
image


## Pre-requisites
- docker
- bash
- tar

There are 2 files in this repo:
- Dockerfile this is the main docker file that will run the steps to build the latest master branch of filecoin-ffi on ubuntu
- run_arm_build_docker.sh - this script runs the docker build and extract the content from the image to the host.

## Running
```
./run_arm_build_docker.sh
```


## Builders
We can use some of these images as builders. They are all arm64 based.
```
FROM --platform=arm64 golang@sha256:96e888160bd68f54a1165b23c66318aea4ff6a4726cb854276d6d776c14b8978 as builder
FROM ubuntu:latest as builder
FROM rust:slim-buster@sha256:5b0c5f6cd5aa84f6dd3f2188ac84aa0e0d602b514ccc14e9d1ebd5b865aa7849 as builder
FROM golang:1.17.9-stretch as builder
```
14 changes: 14 additions & 0 deletions builder/arm64/run_arm_build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

timestamp=$(date +%s)
name=arm_build_only_$timestamp
docker build -t $name .

# get the container id
id=$(docker create $name)
docker cp $id:/filecoin-ffi/ - > $name.tar.gz

## extract
tar -xvf $name.tar.gz

## Copy to wherever..
5 changes: 4 additions & 1 deletion install-filcrypto
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ build_from_source() {
if [ "$(uname -s)" = "Darwin" ] && [ "$(uname -m)" = "x86_64" ]; then
build="lipo"
additional_flags="--targets x86_64-apple-darwin,aarch64-apple-darwin "
else
elif [ "$(uname -m)" = "arm64" ]; then
build="build"
additional_flags="--target aarch64-unknown-linux-gnu "
else
build="build"
fi

Expand Down