diff --git a/.gitmodules b/.gitmodules index 476370f2e..d28fd2dda 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,5 +2,5 @@ path = lib/bls-signatures/bls-signatures url = https://github.com/filecoin-project/bls-signatures.git [submodule "lib/sectorbuilder/rust-builder"] - path = lib/rust-fil-sector-builder + path = lib/sectorbuilder/rust-fil-sector-builder url = https://github.com/filecoin-project/rust-fil-sector-builder diff --git a/Makefile b/Makefile index 2b4150cc4..dec313c0e 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ sectorbuilder: lib/sectorbuilder/include/sector_builder_ffi.h lib/sectorbuilder/include/sector_builder_ffi.h: lib/rust-fil-sector-builder ; ./scripts/install-sectorbuilder.sh -deps: blssigs sectorbuilder +deps: blssigs build: deps go build -o lotus ./cmd/lotus diff --git a/lib/sectorbuilder/libsectorbuilder/cgo_bindings.go b/lib/sectorbuilder/binding/cgo_bindings.go similarity index 99% rename from lib/sectorbuilder/libsectorbuilder/cgo_bindings.go rename to lib/sectorbuilder/binding/cgo_bindings.go index f576fc571..035ced74d 100644 --- a/lib/sectorbuilder/libsectorbuilder/cgo_bindings.go +++ b/lib/sectorbuilder/binding/cgo_bindings.go @@ -1,6 +1,6 @@ // +build !windows -package libsectorbuilder +package sectorbuilder import ( "time" diff --git a/lib/sectorbuilder/libsectorbuilder/cgo_transforms.go b/lib/sectorbuilder/binding/cgo_transforms.go similarity index 99% rename from lib/sectorbuilder/libsectorbuilder/cgo_transforms.go rename to lib/sectorbuilder/binding/cgo_transforms.go index 2dde69496..2c47168b4 100644 --- a/lib/sectorbuilder/libsectorbuilder/cgo_transforms.go +++ b/lib/sectorbuilder/binding/cgo_transforms.go @@ -1,4 +1,4 @@ -package libsectorbuilder +package sectorbuilder import ( "unsafe" diff --git a/scripts/install-sectorbuilder.sh b/lib/sectorbuilder/build.sh similarity index 57% rename from scripts/install-sectorbuilder.sh rename to lib/sectorbuilder/build.sh index 18b1133ce..3a7f1cc8c 100755 --- a/scripts/install-sectorbuilder.sh +++ b/lib/sectorbuilder/build.sh @@ -2,9 +2,10 @@ set -Eeo pipefail -source "$(dirname "${BASH_SOURCE[0]}")/install-shared.bash" +cd "$(dirname "${BASH_SOURCE[0]}")" +source "install-shared.bash" -subm_dir="lib/rust-fil-sector-builder" +subm_dir="rust-fil-sector-builder" git submodule update --init --recursive $subm_dir @@ -12,16 +13,16 @@ if download_release_tarball tarball_path "${subm_dir}"; then tmp_dir=$(mktemp -d) tar -C $tmp_dir -xzf $tarball_path - cp -R "${tmp_dir}/include" lib/sectorbuilder - cp -R "${tmp_dir}/lib" lib/sectorbuilder + cp -R "${tmp_dir}/include" . + cp -R "${tmp_dir}/lib" . else echo "failed to find or obtain precompiled assets for ${subm_dir}, falling back to local build" build_from_source "${subm_dir}" - mkdir -p lib/sectorbuilder/include - mkdir -p lib/sectorbuilder/lib/pkgconfig + mkdir -p include + mkdir -p lib/pkgconfig - find "${subm_dir}" -type f -name sector_builder_ffi.h -exec mv -- "{}" ./lib/sectorbuilder/include/ \; - find "${subm_dir}" -type f -name libsector_builder_ffi.a -exec cp -- "{}" ./lib/sectorbuilder/lib/ \; - find "${subm_dir}" -type f -name sector_builder_ffi.pc -exec cp -- "{}" ./lib/sectorbuilder/pkgconfig/ \; + find "${subm_dir}" -type f -name sector_builder_ffi.h -exec mv -- "{}" include/ \; + find "${subm_dir}" -type f -name libsector_builder_ffi.a -exec cp -- "{}" lib/ \; + find "${subm_dir}" -type f -name sector_builder_ffi.pc -exec cp -- "{}" pkgconfig/ \; fi \ No newline at end of file diff --git a/lib/sectorbuilder/install-shared.bash b/lib/sectorbuilder/install-shared.bash new file mode 100755 index 000000000..51f47c67e --- /dev/null +++ b/lib/sectorbuilder/install-shared.bash @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +download_release_tarball() { + __resultvar=$1 + __submodule_path=$2 + __repo_name=$(echo $2 | cut -d '/' -f 1) + __release_name="${__repo_name}-$(uname)" + __release_sha1=$(git rev-parse @:"${__submodule_path}") + __release_tag="${__release_sha1:0:16}" + __release_tag_url="https://api.github.com/repos/filecoin-project/${__repo_name}/releases/tags/${__release_tag}" + + echo "acquiring release @ ${__release_tag}" + + __release_response=$(curl \ + --retry 3 \ + --location $__release_tag_url) + + __release_url=$(echo $__release_response | jq -r ".assets[] | select(.name | contains(\"${__release_name}\")) | .url") + + if [[ -z "$__release_url" ]]; then + (>&2 echo "failed to download release (tag URL: ${__release_tag_url}, response: ${__release_response})") + return 1 + fi + + __tar_path="/tmp/${__release_name}_$(basename ${__release_url}).tar.gz" + + if [[ ! -f "${__tar_path}" ]]; then + __asset_url=$(curl \ + --head \ + --retry 3 \ + --header "Accept:application/octet-stream" \ + --location \ + --output /dev/null \ + -w %{url_effective} \ + "$__release_url") + + curl --retry 3 --output "${__tar_path}" "$__asset_url" + if [[ $? -ne "0" ]]; then + (>&2 echo "failed to download release asset (tag URL: ${__release_tag_url}, asset URL: ${__asset_url})") + return 1 + fi + fi + + eval $__resultvar="'$__tar_path'" +} + +build_from_source() { + __submodule_path=$1 + __submodule_sha1=$(git rev-parse @:"${__submodule_path}") + __submodule_sha1_truncated="${__submodule_sha1:0:16}" + + echo "building from source @ ${__submodule_sha1_truncated}" + + if ! [ -x "$(command -v cargo)" ]; then + (>&2 echo 'Error: cargo is not installed.') + (>&2 echo 'Install Rust toolchain to resolve this problem.') + exit 1 + fi + + if ! [ -x "$(command -v rustup)" ]; then + (>&2 echo 'Error: rustup is not installed.') + (>&2 echo 'Install Rust toolchain installer to resolve this problem.') + exit 1 + fi + + pushd $__submodule_path + + cargo --version + cargo update + + if [[ -f "./scripts/build-release.sh" ]]; then + ./scripts/build-release.sh $(cat rust-toolchain) + else + cargo build --release --all + fi + + popd +} diff --git a/lib/rust-fil-sector-builder b/lib/sectorbuilder/rust-fil-sector-builder similarity index 100% rename from lib/rust-fil-sector-builder rename to lib/sectorbuilder/rust-fil-sector-builder