Skip to content

Commit 7743366

Browse files
committed
Enable link-time optimization when building Rust library for production
This decreases the compiled library size and improves performance. codegen-units is also set to 1 to further optimize the compiled library.
1 parent 25c5a74 commit 7743366

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

docker/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
2020
# Update PATH for cargo
2121
ENV RUSTUP_HOME=/usr/local/rustup \
2222
CARGO_HOME=/usr/local/cargo \
23+
RUSTFLAGS="-C codegen-units=1" \
24+
CARGO_PROFILE_RELEASE_LTO=fat \
2325
PATH=/usr/local/cargo/bin:$PATH
2426

2527
# Install Rust toolchain, see https://rust-lang.github.io/rustup/installation/other.html

publish_windows.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
pathlib.Path(dst_dir).mkdir(parents=True, exist_ok=True)
2525
pathlib.Path(dst_dir_debug).mkdir(parents=True, exist_ok=True)
2626

27+
# Build GDNative library with production optimizations
28+
subprocess.run(
29+
["cargo", "build", "--release"],
30+
cwd="rust",
31+
env={"RUSTFLAGS": "-C codegen-units=1", "CARGO_PROFILE_RELEASE_LTO": "fat"}
32+
)
33+
2734
# Copy all dlls
2835
src_dir = "godot"
2936
for dll in glob.iglob(os.path.join(src_dir, "*.dll")):

0 commit comments

Comments
 (0)