Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builds: Enable lld, optimize linking more, faster cargo-test build #25116

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
# Sync: This target-cpu and list of features should be kept in sync with the ones in ci-builder and
# xcompile.
rustflags = [
"-C",
"link-arg=-Wl,--compress-debug-sections=zlib-gabi",
"-Clink-arg=-Wl,--compress-debug-sections=zlib",
"-Clink-arg=-Wl,-O2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to apply to local developer builds too, no? I don’t think everyone has easy access to lld.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but on Linux only. I think we should set lld everywhere on Linux actually, and devs who are on Linux should be able to easily install it or override RUSTFLAGS. lld is definitely faster than ld, so I don't see a downside.

Copy link
Member

@benesch benesch Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm somewhat reticent to set any compile flags that will make it so that cargo build doesn't work with a standard Rust installation. Historically the main motivation behind this philosophy has been to encourage external contributions from folks who might not want to customize their toolchains to match Materialize's specifications. That's less of an issue now that we've gone cloud native. But recently @ParkMyCar ran into trouble while trying to get the Fivetran destination deployed because Fivetran's hardware is too old for the target CPU/features we specify in .cargo/config. So I'm increasingly pondering whether we should declare that .cargo/config should be the lowest common denominator, and we'd provide a custom profile like dev-fast for folks who want to opt into faster compiles at the cost of installing extra tools. But that's not viable until custom profiles learn to support configuring rustflags.

Anyway, no qualms with trying this out. We can always find a different course if it proves to be a big problem for external contributors or partners who need to build the repository. Just one ask: can you check with folks in #epd-announce and make sure everyone's up for installing lld? We should also update the developer guide with a note that you need to install lld on Linux (or override rustflags).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The experience with getting the Fivetran Destination built on their hardware definitely surprised me. Also not opposed to adding these for now, but I agree the best approach would be having separate profiles like dev-fast and prod-like, with the default being the lowest common denominator, possibly even no special flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked in #epd-announce but didn't get much feedback either way: https://materializeinc.slack.com/archives/CUXUBJH7B/p1707756913865829

"-Clink-arg=-fuse-ld=lld",
"-Csymbol-mangling-version=v0",
"-Ctarget-cpu=x86-64-v3",
"-Ctarget-feature=+aes",
Expand All @@ -31,8 +32,9 @@ rustflags = [
# xcompile.
[target."aarch64-unknown-linux-gnu"]
rustflags = [
"-C",
"link-arg=-Wl,--compress-debug-sections=zlib-gabi",
"-Clink-arg=-Wl,--compress-debug-sections=zlib",
"-Clink-arg=-Wl,-O2",
"-Clink-arg=-fuse-ld=lld",
"-Csymbol-mangling-version=v0",
"-Ctarget-cpu=neoverse-n1",
"-Ctarget-feature=+aes,+sha2",
Expand All @@ -43,3 +45,7 @@ rustflags = [
# Always reserve at least one core so Cargo doesn't pin our CPU
jobs = -1
rustflags = ["--cfg=tokio_unstable"]

[profile.ci]
inherits = "dev"
debug = "line-tables-only"
2 changes: 2 additions & 0 deletions ci/test/cargo-test/mzcompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
"build",
"--bin",
"clusterd",
"--profile=ci",
],
env=env,
)
Expand All @@ -138,6 +139,7 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
"nextest",
"run",
"--profile=ci",
"--cargo-profile=ci",
f"--partition=count:{partition}/{total}",
# Most tests don't use 100% of a CPU core, so run two tests per CPU.
# TODO(def-): Reenable when #19931 is fixed
Expand Down
1 change: 1 addition & 0 deletions ci/test/pipeline.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ steps:
artifact_paths: [junit_*.xml, target/nextest/ci/junit_cargo-test.xml]
inputs:
- Cargo.lock
- ".config/nextest.toml"
- "**/Cargo.toml"
- "**/*.rs"
- "**/*.proto"
Expand Down
3 changes: 2 additions & 1 deletion doc/developer/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ you'll need a working C and C++ toolchain. You'll also need to install:
* The [CMake] build system
* libclang
* PostgreSQL
* lld (on Linux, or set a custom `RUSTFLAGS`)

On macOS, if you install [Homebrew], you'll be guided through the process of
installing Apple's developer tools, which includes a C compiler and libclang.
Expand All @@ -29,7 +30,7 @@ On Debian-based Linux variants, it's even easier:

```shell
sudo apt update
sudo apt install build-essential cmake postgresql-client libclang-dev
sudo apt install build-essential cmake postgresql-client libclang-dev lld
```

On other platforms, you'll have to figure out how to get these tools yourself.
Expand Down