2019-08-02 18:40:30 -06:00
|
|
|
#!/bin/sh -e
|
2020-03-12 08:57:09 -06:00
|
|
|
#
|
2021-09-02 00:35:05 -06:00
|
|
|
# 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.
|
2020-03-12 08:57:09 -06:00
|
|
|
export CARGO_HOME=$PWD
|
2019-10-08 02:22:32 -06:00
|
|
|
|
2021-09-02 00:35:05 -06:00
|
|
|
# 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.
|
2020-03-12 08:57:09 -06:00
|
|
|
(
|
|
|
|
cd vendor
|
|
|
|
|
2021-09-02 00:35:05 -06:00
|
|
|
# Download link for this crate 404s. Mirror link saves the file as
|
|
|
|
# 'download' so it must be renamed.
|
2021-07-10 11:40:15 -06:00
|
|
|
mv -f download wasi-0.9.0+wasi-snapshot-preview1.crate
|
|
|
|
|
2020-03-12 08:57:09 -06:00
|
|
|
for crate in *.crate; do
|
|
|
|
tar xf "$crate"
|
|
|
|
|
|
|
|
# Strip the filename from the sha256sum output.
|
|
|
|
sha256=$(sha256sum "$crate")
|
|
|
|
sha256=${sha256%% *}
|
|
|
|
|
|
|
|
printf '{"package":"%s","files":{}}\n' "$sha256" \
|
|
|
|
> "${crate%.crate}/.cargo-checksum.json"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
|
2021-09-02 00:35:05 -06:00
|
|
|
# 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.
|
2020-03-12 08:57:09 -06:00
|
|
|
mkdir -p .cargo
|
|
|
|
|
2021-09-02 00:35:05 -06:00
|
|
|
# Create the configuration file to tell cargo to look in the 'vendor' directory
|
|
|
|
# for the already downloaded sources rather than crates.io (over network).
|
2020-03-12 08:57:09 -06:00
|
|
|
cat <<EOF > .cargo/config
|
|
|
|
[source.crates-io]
|
|
|
|
replace-with = "vendored-sources"
|
|
|
|
|
|
|
|
[source.vendored-sources]
|
|
|
|
directory = "vendor"
|
|
|
|
EOF
|
|
|
|
|
2021-09-02 00:35:05 -06:00
|
|
|
# Use the '--frozen' flag to tell cargo to skip the network and use whatever
|
|
|
|
# dependencies are in the Cargo.[toml|lock] files.
|
2021-07-05 15:38:59 -06:00
|
|
|
cargo build --release --frozen
|
2019-10-08 02:22:32 -06:00
|
|
|
|
2021-07-01 10:26:38 -06:00
|
|
|
mkdir -p "$1/usr/bin"
|
|
|
|
cp -f target/release/cbindgen "$1/usr/bin"
|