-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Tweak the organisation of the build config
The goal is enable us to add distro-toolchain specific compile time options trivially, whilst still having reasonably conservative onboarding defaults, such that users can successfully run `just get-started` on a variety of distributions. By setting os_release_id="(...)" in build.rs in boulder/ and moss/, we can now add specific flags known to work on platforms where we control the toolchain build-time options. As of now, the logic is working well enough that compilation doesn't stop working if you're not on Solus. The current solution is meant as starting point for a potentially more refined future solution if necessary. Tested on fedora 39 and Solus. Signed-off-by: Rune Morling <[email protected]>
- Loading branch information
Showing
7 changed files
with
96 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,42 @@ | ||
[target."x86_64-unknown-linux-gnu"] | ||
# - On systems that do not use lld as the system linker (such as Solus) using lld directly saves about a second | ||
# of build time for incremental compiles for building boulder (from 2.191s to 1.198s on my machine). | ||
# - Compressing debug symbols with zstd shrinks the dev profile boulder binary from 206.03MB to 81.44MB, a 124.59MB | ||
# or ~60% savings. It doesn't affect the binary size for packaging builds since we strip those, but the debug symbols | ||
# are reduced in size from 113.16MB to 34.63MB. It adds about ~152ms to the build times which is less than we gained | ||
# by switching to lld | ||
# - The new symbol mangling format (https://doc.rust-lang.org/rustc/symbol-mangling/v0.html) improves the backtrace | ||
# shown by RUST_BACKTRACE=1 and other debug utilities. It should also be helpful once we have ABI reports. Upstream | ||
# hasn't switched to it yet by default due to stable distros not having new enough tools, but that doesn't matter for us | ||
# Having a way to detect on which system we are compiled means we can get | ||
# away with adding rustflags here that we know are present in the system | ||
# toolchain builds. | ||
# | ||
# We can set these extra flags via matching on a target cfg() expression. | ||
# | ||
# - On systems that do not use lld as the system linker (such as Solus) using | ||
# lld directly saves about a second of build time for incremental compiles | ||
# for building boulder (from 2.191s to 1.198s on Reilly's machine). | ||
# | ||
# - In testing, compression of debug symbols with zstd shrinks the dev profile | ||
# boulder binary from 206.03MB to 81.44MB, a 124.59MB or ~60% savings. | ||
# It doesn't affect the binary size for packaging builds since we strip those, | ||
# but the debug symbols are reduced in size from 113.16MB to 34.63MB. | ||
# It adds about ~152ms to the build times which is less than we gained by | ||
# switching to lld. This feature requires a compiler compiled with support | ||
# for zstd debug symbols. | ||
# | ||
# - The new symbol mangling format[1] improves the backtrace shown by | ||
# RUST_BACKTRACE=1 and other debug utilities. It should also be helpful once | ||
# we have ABI reports. Upstream hasn't switched to it yet by default due to | ||
# stable distros not having new enough tools, but that doesn't matter for us | ||
# [1]: https://doc.rust-lang.org/rustc/symbol-mangling/v0.html | ||
# | ||
|
||
# NB: os_release patterns need to be added to both target configs for this to | ||
# work... | ||
# | ||
# The Solus toolchain supports zstd debug sections currently (Serpent doesn't) | ||
[target.'cfg(any(os_release_id = "solus"))'] | ||
rustflags = [ | ||
"-Clink-arg=-fuse-ld=lld", | ||
"-Clink-arg=-Wl,--compress-debug-sections=zstd", | ||
"-Csymbol-mangling-version=v0", | ||
] | ||
|
||
[target."aarch64-unknown-linux-gnu"] | ||
# Default flags | ||
[target.'cfg(not(any(os_release_id = "solus")))'] | ||
rustflags = [ | ||
"-Clink-arg=-fuse-ld=lld", | ||
"-Clink-arg=-Wl,--compress-debug-sections=zstd", | ||
"-Csymbol-mangling-version=v0", | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use etc_os_release::OsRelease; | ||
use std::error::Error; | ||
|
||
/// Set cargo::rustc-cfg=os_release_id="whatever" when /etc/os-release warrants it. | ||
/// The intent is to enable trivial conditional compilation via [target.'cfg(...)'] | ||
/// stanzas. | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
// only recompile when necessary | ||
println!("cargo::rerun-if-changed=./build.rs"); | ||
// if /etc/os-release doesn't exist, we have a problem big enough that it's OK to crash | ||
let os_release = OsRelease::open()?; | ||
println!("cargo::rustc-cfg=os_release_id=\"{}\"", os_release.id()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use etc_os_release::OsRelease; | ||
use std::error::Error; | ||
|
||
/// Set cargo::rustc-cfg=os_release_id="whatever" when /etc/os-release warrants it. | ||
/// The intent is to enable trivial conditional compilation via [target.'cfg(...)'] | ||
/// stanzas. | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
// only recompile when necessary | ||
println!("cargo::rerun-if-changed=./build.rs"); | ||
// if /etc/os-release doesn't exist, we have a problem big enough that it's OK to crash | ||
let os_release = OsRelease::open()?; | ||
println!("cargo::rustc-cfg=os_release_id=\"{}\"", os_release.id()); | ||
|
||
Ok(()) | ||
} |