diff --git a/.buildkite/pipeline_pr.py b/.buildkite/pipeline_pr.py index 33828fb097f4..7ae27854d427 100755 --- a/.buildkite/pipeline_pr.py +++ b/.buildkite/pipeline_pr.py @@ -49,7 +49,7 @@ release_grp = group( "📦 Release Sanity Build", - "./tools/devtool -y sh ./tools/release.sh --libc musl --profile release --make-release", + "mkdir -p ./test_results && touch ./test_results/test-report.json && ./tools/devtool -y sh ./tools/release.sh --libc musl --profile release --make-release", **defaults_once_per_architecture, ) diff --git a/.cargo/config b/.cargo/config index 73375de08a2e..a50af8c383cd 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,6 +1,5 @@ [build] target-dir = "build/cargo_target" -target = "x86_64-unknown-linux-musl" rustflags = [ "-Wclippy::ptr_as_ptr", "-Wclippy::undocumented_unsafe_blocks", diff --git a/tests/integration_tests/build/test_binary_static_linking.py b/tests/integration_tests/build/test_binary_static_linking.py new file mode 100644 index 000000000000..fabcb8a66ac0 --- /dev/null +++ b/tests/integration_tests/build/test_binary_static_linking.py @@ -0,0 +1,22 @@ +# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 +"""Tests to check if the release binary is statically linked. + +""" + +import pytest +import host_tools.cargo_build as host +from framework import utils + +@pytest.mark.timeout(500) +def test_firecracker_binary_static_linking(): + """ + Test to make sure the firecracker binary is statically linked. + """ + fc_binary_path = host.get_binary("firecracker") + _, stdout,stderr = utils.run_cmd(f"file {fc_binary_path}") + assert "" in stderr + # expected "statically linked" for aarch64 and + # "static-pie linked" for x86_64 + assert "statically linked" in stdout or \ + "static-pie linked" in stdout diff --git a/tools/devtool b/tools/devtool index f6e990a7aad1..fb20139ff131 100755 --- a/tools/devtool +++ b/tools/devtool @@ -483,7 +483,7 @@ cmd_build() { } function cmd_make_release { - cmd_test -- --json-report --json-report-file=test-report.json || die "Tests failed!" + cmd_test || die "Tests failed!" run_devctr \ --user "$(id -u):$(id -g)" \ diff --git a/tools/release.sh b/tools/release.sh index 1c84e5106bba..b5cfc6eeb308 100755 --- a/tools/release.sh +++ b/tools/release.sh @@ -134,6 +134,16 @@ cargo build --target "$CARGO_TARGET" $CARGO_OPTS --workspace say "Binaries placed under $CARGO_TARGET_DIR" +# Check static linking: +# expected "statically linked" for aarch64 and +# "static-pie linked" for x86_64 +binary_format=$(file $CARGO_TARGET_DIR/firecracker) +if [[ "$PROFILE" = "release" + && "$binary_format" != *"statically linked"* + && "$binary_format" != *"static-pie linked"* ]]; then + die "Binary not statically linked: $binary_format" +fi + # # # # Make a release if [ -z "$MAKE_RELEASE" ]; then exit 0 @@ -157,7 +167,7 @@ cp -v -t "$RELEASE_DIR" LICENSE NOTICE THIRD-PARTY check_swagger_artifact src/api_server/swagger/firecracker.yaml "$VERSION" cp -v src/api_server/swagger/firecracker.yaml "$RELEASE_DIR/firecracker_spec-$VERSION.yaml" -cp -v tests/test-report.json "$RELEASE_DIR/" +cp -v test_results/test-report.json "$RELEASE_DIR/" ( cd "$RELEASE_DIR"