Skip to content

Commit

Permalink
enhancement: use codegen_units/lto for release
Browse files Browse the repository at this point in the history
Signed-off-by: Kirill Fomichev <fanatid@ya.ru>
  • Loading branch information
fanatid committed Jan 24, 2021
1 parent da99f18 commit 6c6f7ee
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ name = "graphql-schema"
path = "src/api/schema/gen.rs"
required-features = ["default-no-api-client"]

[profile.release]
lto = true
codegen-units = 1

[profile.bench]
debug = true

Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ environment-push: environment-prepare ## Publish a new version of the container

##@ Building
.PHONY: build
build: export RUSTFLAGS += -C link-arg=-s
build: export CFLAGS += -g0 -O3
build: ## Build the project in release mode (Supports `ENVIRONMENT=true`)
${MAYBE_ENVIRONMENT_EXEC} cargo build --release --no-default-features --features ${DEFAULT_FEATURES}
${MAYBE_ENVIRONMENT_COPY_ARTIFACTS}
Expand Down Expand Up @@ -215,6 +217,7 @@ cross-%: export COMMAND ?=$(word 1,${PAIR})
cross-%: export TRIPLE ?=$(subst ${SPACE},-,$(wordlist 2,99,${PAIR}))
cross-%: export PROFILE ?= release
cross-%: export RUSTFLAGS += -C link-arg=-s
cross-%: export CFLAGS += -g0 -O3
cross-%: cargo-install-cross
$(MAKE) -k cross-image-${TRIPLE}
cross ${COMMAND} \
Expand All @@ -227,6 +230,7 @@ target/%/vector: export PAIR =$(subst /, ,$(@:target/%/vector=%))
target/%/vector: export TRIPLE ?=$(word 1,${PAIR})
target/%/vector: export PROFILE ?=$(word 2,${PAIR})
target/%/vector: export RUSTFLAGS += -C link-arg=-s
target/%/vector: export CFLAGS += -g0 -O3
target/%/vector: cargo-install-cross CARGO_HANDLES_FRESHNESS
$(MAKE) -k cross-image-${TRIPLE}
cross build \
Expand Down Expand Up @@ -515,6 +519,8 @@ test-cli: ## Runs cli tests
test-wasm-build-modules: $(WASM_MODULE_OUTPUTS) ### Build all WASM test modules

$(WASM_MODULE_OUTPUTS): MODULE = $(notdir $@)
$(WASM_MODULE_OUTPUTS): export RUSTFLAGS += -C link-arg=-s
$(WASM_MODULE_OUTPUTS): export CFLAGS += -g0 -O3
$(WASM_MODULE_OUTPUTS): ### Build a specific WASM module
@echo "# Building WASM module ${MODULE}, requires Rustc for wasm32-wasi."
${MAYBE_ENVIRONMENT_EXEC} cargo build \
Expand Down
22 changes: 14 additions & 8 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ if [ -f "$BINARY_PATH" ] && [ "$OVERWRITE" == "false" ]; then
exit 0
fi

#
# CFLAGS
#

export CFLAGS="$CFLAGS -g0 -O3"

#
# Strip the output binary through RUSTFLAGS
#

if [ "$KEEP_SYMBOLS" != "false" ]; then
export RUSTFLAGS="$RUSTFLAGS -C link-arg=-s"
fi

#
# Header
#
Expand Down Expand Up @@ -84,11 +98,3 @@ if [ "$FEATURES" == "default" ]; then
else
cargo build "${BUILD_FLAGS[@]}" --no-default-features --features "$FEATURES"
fi

#
# Strip the output binary
#

if [ "$KEEP_SYMBOLS" == "false" ]; then
strip "$BINARY_PATH"
fi
13 changes: 0 additions & 13 deletions scripts/slim-builds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,4 @@ panic = 'unwind'
# incremental = true
codegen-units = 256
rpath = false
[profile.release]
# See defaults https://doc.rust-lang.org/cargo/reference/profiles.html#release
opt-level = 3
debug = false
debug-assertions = false
overflow-checks = false
lto = false
panic = 'unwind'
# Disabled, see build.incremental
# incremental = false
codegen-units = 1
rpath = false
EOF

0 comments on commit 6c6f7ee

Please sign in to comment.