From 31bf9188d999cfcfbcc065ba5cf236dcfd15cb9d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 2 Sep 2021 09:35:05 +0300 Subject: [PATCH] cbindgen: trim build directories from binary --- extra/cbindgen/build | 46 ++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/extra/cbindgen/build b/extra/cbindgen/build index 6555b338..c7b24be1 100755 --- a/extra/cbindgen/build +++ b/extra/cbindgen/build @@ -1,27 +1,26 @@ #!/bin/sh -e # -# Seeing as this is the only rust package in the -# repositories (other than rust itself), this will -# also serve as a reference to writing network-free -# rust-based packages. +# Seeing as this is the only rust package in the repositories (other than rust +# itself), this will also serve as a reference to writing network-free rust +# based packages. -# Set the CARGO_HOME variable to the current directory -# to prevent cargo from touching '$HOME/.cargo'. This -# keeps the build contained to the package manager's -# domain. +# Set the CARGO_HOME variable to the current directory to prevent cargo from +# touching '$HOME/.cargo'. This keeps the build contained to the package +# manager's domain. export CARGO_HOME=$PWD -# Extract each crate and generate a checksum file. -# This effectively mimics 'cargo vendor' without the -# network requirement. -# -# This allows the package manager to cache each crate -# and handle them as regular sources. +# Instruct the compiler to trim absolute paths in resulting binaries and instead +# change them to relative paths ($PWD/... ./...). +export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix=$PWD=." + +# Extract each crate and generate a checksum file. This effectively mimics +# 'cargo vendor' without the network requirement. This allows the package +# manager to cache each crate and handle them as regular sources. ( cd vendor - # Download link for this crate 404s. Mirror link saves - # the file as 'download' so it must be renamed. + # Download link for this crate 404s. Mirror link saves the file as + # 'download' so it must be renamed. mv -f download wasi-0.9.0+wasi-snapshot-preview1.crate for crate in *.crate; do @@ -36,14 +35,12 @@ export CARGO_HOME=$PWD done ) -# Cargo reads a "global" configuration file from $CARGO_HOME, -# as we've set it to $PWD this is where we'll be storing the -# vendor config. +# Cargo reads a "global" configuration file from $CARGO_HOME, as we've set it to +# $PWD this is where we'll be storing the vendor config. mkdir -p .cargo -# Create the configuration file to tell cargo to look in the -# 'vendor' directory for the already downloaded sources -# rather than crates.io (over network). +# Create the configuration file to tell cargo to look in the 'vendor' directory +# for the already downloaded sources rather than crates.io (over network). cat < .cargo/config [source.crates-io] replace-with = "vendored-sources" @@ -52,9 +49,8 @@ replace-with = "vendored-sources" directory = "vendor" EOF -# Use the '--frozen' flag to tell cargo to skip the network -# and use whatever dependencies are in the Cargo.[toml|lock] -# files. +# Use the '--frozen' flag to tell cargo to skip the network and use whatever +# dependencies are in the Cargo.[toml|lock] files. cargo build --release --frozen mkdir -p "$1/usr/bin"