Skip to content

Commit

Permalink
perf: Use LTO in image builds (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky authored Oct 16, 2024
1 parent a17f38f commit 9ebec5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ categories = ["game-development", "network-programming"]
edition.workspace = true
exclude = ["docs", "build", "examples", "image"]

[profile.lto]
inherits = "release"
opt-level = 3
codegen-units = 1
lto = "fat"

[features]
default = []
instrument = []
mimalloc = ["dep:mimalloc"]
heap-stats = ["dep:crossbeam-utils"]


[lints]
workspace = true

Expand Down
8 changes: 4 additions & 4 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ kube_mount_args := -v $(kubeconfig_path):/root/.kube -v $(helm_config):/root/.co
minikube_args := --network=host -v ~/.minikube:$(HOME)/.minikube
gcloud_mount_args := -v $(build_path)/.config/gcloud:/root/.config/gcloud

cargo_build_x86_64_linux := build --release --target x86_64-unknown-linux-gnu
cargo_build_x86_64_linux := build --profile=lto --target x86_64-unknown-linux-gnu
cargo_build_x86_64_apple := build --release --target x86_64-apple-darwin
cargo_build_aarch64-apple := build --release --target aarch64-apple-darwin
cargo_build_x86_64_windows := build --release --target x86_64-pc-windows-gnu
Expand Down Expand Up @@ -140,7 +140,7 @@ gen-protobuf: ensure-build-image
# Build an archive all binaries
binary-archive: ensure-build-image build-licence-report build-all-binaries
docker run --rm $(common_rust_args) -w $(CARGO_TARGET_DIR) \
--entrypoint=bash $(BUILD_IMAGE_TAG) -c 'cp ../../license.html . && zip ../../quilkin-$(package_version).zip ./*/release/quilkin ./*/release/quilkin.exe ./license.html'
--entrypoint=bash $(BUILD_IMAGE_TAG) -c 'cp ../../license.html . && zip ../../quilkin-$(package_version).zip ./*/lto/quilkin ./*/lto/quilkin.exe ./license.html'

# Build binary for x86_64-unknown-linux-gnu.
# Use BUILD_LOCAL=1 to build through local cargo rather than through the build container.
Expand Down Expand Up @@ -188,9 +188,9 @@ build-image: ensure-build-image build-licence-report build-linux-binary
build-image:
-mkdir -p "$(project_path)/target/image/"
ifdef BUILD_LOCAL
cp "$(project_path)/target/x86_64-unknown-linux-gnu/release/quilkin" "$(project_path)/target/image/"
cp "$(project_path)/target/x86_64-unknown-linux-gnu/lto/quilkin" "$(project_path)/target/image/"
else
cp "$(project_path)/target/build-image/x86_64-unknown-linux-gnu/release/quilkin" "$(project_path)/target/image/"
cp "$(project_path)/target/build-image/x86_64-unknown-linux-gnu/lto/quilkin" "$(project_path)/target/image/"
endif
docker run --rm $(common_rust_args) \
--entrypoint=bash $(BUILD_IMAGE_TAG) -c './image/archive_dependencies.sh'
Expand Down

0 comments on commit 9ebec5a

Please sign in to comment.