Skip to content

Commit

Permalink
macros: adjust rust flags and cache directory
Browse files Browse the repository at this point in the history
The cache directory is meant to optimize subsequent rebuilds of the
crates in the "os" package. We weren't seeing much benefit for two
reasons.

First, when building the apiclient and the migrations with the musl
target, we were clobbering the cache for the gnu target, which then
needed to be rebuilt the next time around.

Second, in 8f9306c we left it up to cargo to decide which flags to
pass to rustc for LTO. It passed `-Clinker-plugin-lto` for apiclient
but not for the migrations, so the cache was immediately invalidated
and needed to be rebuilt.

We solve these problems by using a separate cache directory for the
gnu and musl targets, and by specifying the rustc flags we expect.

Signed-off-by: Ben Cressey <bcressey@amazon.com>
  • Loading branch information
bcressey committed Aug 17, 2020
1 parent e0ddf1b commit c66da50
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion macros/cargo
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
%__cargo_cross_opts %{__cargo_common_opts} --target %{__cargo_target}
%__cargo_cross_opts_static %{__cargo_common_opts} --target %{__cargo_target_static}
%__cargo_env CARGO_TARGET_DIR="${HOME}/.cache" SKIP_README="true"
%__cargo_env_static CARGO_TARGET_DIR="${HOME}/.cache/.static" SKIP_README="true"
%__cargo_cross_pkg_config PKG_CONFIG_PATH="%{_cross_pkgconfigdir}" PKG_CONFIG_ALLOW_CROSS=1
%__cargo_cross_env %{__cargo_env} %{__cargo_cross_pkg_config} TARGET_CC="%{_cross_triple}-gnu-gcc"
%__cargo_cross_env_static %{__cargo_env} %{__cargo_cross_pkg_config} TARGET_CC="%{_cross_triple}-musl-gcc" CARGO_PROFILE_RELEASE_LTO=thin
%__cargo_cross_env_static %{__cargo_env_static} %{__cargo_cross_pkg_config} TARGET_CC="%{_cross_triple}-musl-gcc"

%cargo_prep (\
%{__mkdir} -p %{_builddir}/.cargo \
Expand Down
2 changes: 1 addition & 1 deletion macros/rust
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
%__global_rustflags_shared -Cprefer-dynamic %__global_rustflags

# Enable LTO and static C runtime.
%__global_rustflags_static -Ctarget-feature=+crt-static -Clink-arg=-lgcc %__global_rustflags
%__global_rustflags_static -Clto=thin -Cembed-bitcode=yes -Ctarget-feature=+crt-static -Clink-arg=-lgcc %__global_rustflags

%__global_rustflags_shared_toml [%{lua:
for arg in string.gmatch(rpm.expand("%{__global_rustflags_shared}"), "%S+") do
Expand Down
4 changes: 2 additions & 2 deletions packages/os/os.spec
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ for p in \
done

for p in apiclient ; do
install -p -m 0755 ${HOME}/.cache/%{__cargo_target_static}/release/${p} %{buildroot}%{_cross_bindir}
install -p -m 0755 ${HOME}/.cache/.static/%{__cargo_target_static}/release/${p} %{buildroot}%{_cross_bindir}
done

install -d %{buildroot}%{_cross_sbindir}
Expand All @@ -227,7 +227,7 @@ for version_path in %{_builddir}/sources/api/migration/migrations/*; do
version="${version_path##*/}"
crate_name="${migration_path##*/}"
migration_binary_name="migrate_${version}_${crate_name#migrate-}"
built_path="${HOME}/.cache/%{__cargo_target_static}/release/${crate_name}"
built_path="${HOME}/.cache/.static/%{__cargo_target_static}/release/${crate_name}"
target_path="%{buildroot}%{_cross_datadir}/migrations/${migration_binary_name}"

install -m 0555 "${built_path}" "${target_path}"
Expand Down

0 comments on commit c66da50

Please sign in to comment.