iced/build/build-rust

271 lines
7.0 KiB
Bash
Executable File

#!/bin/sh
set -e
root_dir=$(dirname "$0")
root_dir=$(cd "$root_dir/.." && pwd)
if [ ! -f "$root_dir/LICENSE.txt" ]; then
echo "Couldn't find the root dir"
exit 1
fi
configuration=Release
full_check=y
gen_check=y
has_dotnet=y
has_msrv=y
set_rustflags=y
# Minimum supported Rust version
msrv="1.42.0"
new_func() {
echo
echo "****************************************************************"
echo "$1"
echo "****************************************************************"
echo
}
clean_dotnet_build_output() {
dotnet clean -v:m -c $configuration "$root_dir/src/csharp/Iced.sln"
}
generator_check() {
new_func "Run generator, verify no diff"
dotnet run -c $configuration -p "$root_dir/src/csharp/Intel/Generator/Generator.csproj"
git diff --exit-code
}
test_valid_invalid_instructions() {
new_func "Decode valid and invalid instructions"
valid_file=$(mktemp)
invalid_file=$(mktemp)
# Needs to be rebuilt if the wrong #defines were used
clean_dotnet_build_output
for bitness in 16 32 64; do
echo "==== ${bitness}-bit: Generating valid/invalid files ===="
dotnet run -c:$configuration -p "$root_dir/src/csharp/Intel/IcedFuzzer/IcedFuzzer/IcedFuzzer.csproj" -- -$bitness -oil "$invalid_file" -ovlc "$valid_file"
echo "==== ${bitness}-bit: Testing valid instructions ===="
cargo run --color always --release --manifest-path "$root_dir/src/rust/Cargo.toml" -p iced-x86-fzgt -- -b $bitness -f "$valid_file"
echo "==== ${bitness}-bit: Testing invalid instructions ===="
cargo run --color always --release --manifest-path "$root_dir/src/rust/Cargo.toml" -p iced-x86-fzgt -- -b $bitness -f "$invalid_file" --invalid
done
for bitness in 16 32 64; do
echo "==== ${bitness}-bit (AMD): Generating valid/invalid files ===="
dotnet run -c:$configuration -p "$root_dir/src/csharp/Intel/IcedFuzzer/IcedFuzzer/IcedFuzzer.csproj" -- -$bitness -oil "$invalid_file" -ovlc "$valid_file" --amd
echo "==== ${bitness}-bit (AMD): Testing valid instructions ===="
cargo run --color always --release --manifest-path "$root_dir/src/rust/Cargo.toml" -p iced-x86-fzgt -- -b $bitness -f "$valid_file" --amd
echo "==== ${bitness}-bit (AMD): Testing invalid instructions ===="
cargo run --color always --release --manifest-path "$root_dir/src/rust/Cargo.toml" -p iced-x86-fzgt -- -b $bitness -f "$invalid_file" --invalid --amd
done
rm "$valid_file"
rm "$invalid_file"
}
build_no_std() {
new_func "Build no_std"
curr_dir=$(pwd)
cd "$root_dir/src/rust/iced-x86"
echo "==== BUILD DEBUG ===="
cargo check --color always --no-default-features --features "no_std decoder encoder block_encoder op_code_info instr_info gas intel masm nasm fast_fmt db"
cd "$curr_dir"
}
build_features() {
new_func "Build one feature at a time"
curr_dir=$(pwd)
cd "$root_dir/src/rust/iced-x86"
set -- \
"std decoder" \
"std encoder" \
"std encoder block_encoder" \
"std encoder op_code_info" \
"std instr_info" \
"std gas" \
"std intel" \
"std masm" \
"std nasm" \
"std fast_fmt"
for features in "$@"; do
echo "==== $features ===="
cargo check --color always --release --no-default-features --features "$features"
done
set -- \
"no_vex" \
"no_evex" \
"no_xop" \
"no_d3now" \
"no_vex no_evex no_xop no_d3now"
for features in "$@"; do
echo "==== $features ===="
cargo check --color always --release --features "$features"
done
set -- \
"no_std decoder" \
"no_std encoder" \
"no_std encoder block_encoder" \
"no_std encoder op_code_info" \
"no_std instr_info" \
"no_std gas" \
"no_std intel" \
"no_std masm" \
"no_std nasm" \
"no_std fast_fmt"
for features in "$@"; do
echo "==== $features ===="
cargo check --color always --release --no-default-features --features "$features"
done
set -- \
"std decoder" \
"std decoder encoder" \
"std decoder encoder block_encoder" \
"std decoder encoder op_code_info" \
"std decoder instr_info" \
"std decoder gas" \
"std decoder intel" \
"std decoder masm" \
"std decoder nasm" \
"std decoder fast_fmt"
for features in "$@"; do
echo "==== TEST $features ===="
cargo check --color always --release --tests --no-default-features --features "$features"
done
set -- \
"no_vex" \
"no_evex" \
"no_xop" \
"no_d3now" \
"no_vex no_evex no_xop no_d3now"
for features in "$@"; do
echo "==== TEST $features ===="
cargo check --color always --release --tests --features "$features"
done
cd "$curr_dir"
}
build_test_default() {
new_func "Build, test (default)"
curr_dir=$(pwd)
cd "$root_dir/src/rust/iced-x86"
echo "Rust version"
rustc --version
echo "==== CLIPPY RELEASE ===="
cargo clippy --color always --release
echo "==== CLIPPY RELEASE --tests ===="
cargo clippy --color always --release --tests
echo "==== FORMAT CHECK ===="
cargo fmt -- --color always --check
echo "==== DOC ===="
cargo doc --color always
echo "==== BUILD RELEASE ===="
cargo build --color always --features "db" --release
echo "==== TEST RELEASE ===="
cargo test --color always --features "db" --release
# Make sure the two read-mem methods behave the same
echo "==== TEST RELEASE: std decoder __internal_mem_vsib ===="
cargo test --no-default-features --features "std decoder __internal_mem_vsib" --tests
echo "==== TEST DEBUG ===="
cargo test --color always --features "db"
echo "==== BUILD RELEASE wasm32-unknown-unknown ===="
cargo check --color always --features "db" --target wasm32-unknown-unknown --release
echo "==== PUBLISH DRY-RUN ===="
# It fails on Windows (GitHub CI) without this, claiming that some random number of Rust files are dirty.
# Redirect to /dev/null so it won't hang (waiting for us to scroll) if it finds modified lines
git status > /dev/null
git diff > /dev/null
cargo publish --color always --dry-run
cd "$curr_dir"
}
build_test_msrv() {
new_func "Build minimum supported Rust version: $msrv"
curr_dir=$(pwd)
cd "$root_dir/src/rust/iced-x86"
echo "*** If this fails, install Rust $msrv or use --no-msrv"
echo "==== UPDATE Cargo.lock ===="
cargo +$msrv generate-lockfile
echo "==== BUILD RELEASE ===="
cargo +$msrv build --color always --features "db" --release
echo "==== TEST RELEASE ===="
cargo +$msrv test --color always --features "db" --release
# Restore it
cargo generate-lockfile
cd "$curr_dir"
}
while [ "$#" -gt 0 ]; do
case $1 in
--quick-check) full_check=n ;;
--no-gen-check) gen_check=n ;;
--no-dotnet) has_dotnet=n ;;
--no-msrv) has_msrv=n ;;
--no-set-rustflags) set_rustflags=n ;;
*) echo "Unknown arg: $1"; exit 1 ;;
esac
shift
done
echo
echo "=================================================="
echo "Rust build"
echo "=================================================="
echo
if [ "$set_rustflags" = "y" ]; then
export RUSTFLAGS="-D warnings"
fi
echo "rustup show"
rustup show
if [ "$full_check" = "y" ]; then
if [ "$has_dotnet" = "y" ]; then
echo "dotnet version (if this fails, install .NET or use --no-dotnet)"
dotnet --version
if [ "$gen_check" = "y" ]; then
generator_check
fi
test_valid_invalid_instructions
fi
build_no_std
build_features
fi
build_test_default
if [ "$full_check" = "y" ] && [ "$has_msrv" = "y" ]; then
build_test_msrv
fi