Prepare sectorbuilder for extraction

This commit is contained in:
Łukasz Magiera 2019-07-17 00:09:40 +02:00
parent f6bca82e82
commit 2c9ad786a4
7 changed files with 92 additions and 13 deletions

2
.gitmodules vendored
View File

@ -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

View File

@ -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

View File

@ -1,6 +1,6 @@
// +build !windows
package libsectorbuilder
package sectorbuilder
import (
"time"

View File

@ -1,4 +1,4 @@
package libsectorbuilder
package sectorbuilder
import (
"unsafe"

View File

@ -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

View File

@ -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
}