From 8180d1619063224b9d2c8323dfac1f60e551dc56 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Mon, 28 Apr 2025 22:08:52 +0100 Subject: [PATCH 1/2] Check `as-if-std` only on nightly --- .github/workflows/main.yml | 3 +++ ci/run.sh | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 25d925dd0..e1b4fc05e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -137,8 +137,11 @@ jobs: # Test that including as a submodule will still work, both with and without # the `backtrace` feature enabled. + # Building as if part of std requires nightly features to be available - run: cargo build --manifest-path crates/as-if-std/Cargo.toml + if: matrix.rust == 'nightly' - run: cargo build --manifest-path crates/as-if-std/Cargo.toml --no-default-features + if: matrix.rust == 'nightly' windows_arm64: name: Windows AArch64 diff --git a/ci/run.sh b/ci/run.sh index 166b387e4..48b5e9bac 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -3,4 +3,6 @@ set -ex cargo test --target $TARGET -cargo build --target $TARGET --manifest-path crates/as-if-std/Cargo.toml +if rustc --version | grep nightly; then + cargo build --target $TARGET --manifest-path crates/as-if-std/Cargo.toml +fi From 2b48d7c9514d1d4ee3b12191fa8ad62ae9b29767 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Tue, 1 Apr 2025 16:00:37 +0100 Subject: [PATCH 2/2] Add `optimize(size)` to some particularly large functions --- crates/as-if-std/src/lib.rs | 2 +- src/symbolize/gimli.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/as-if-std/src/lib.rs b/crates/as-if-std/src/lib.rs index 89ed961f5..6d57ded35 100644 --- a/crates/as-if-std/src/lib.rs +++ b/crates/as-if-std/src/lib.rs @@ -2,7 +2,7 @@ // submodule into the standard library. We try to set this crate up similarly // to the standard library itself to minimize the likelihood of issues when // updating the `backtrace` crate. - +#![feature(optimize_attribute)] #![no_std] extern crate alloc; diff --git a/src/symbolize/gimli.rs b/src/symbolize/gimli.rs index e92f98b5b..04fed66b2 100644 --- a/src/symbolize/gimli.rs +++ b/src/symbolize/gimli.rs @@ -114,6 +114,8 @@ struct Context<'a> { } impl<'data> Context<'data> { + // #[feature(optimize_attr)] is enabled when we're built inside libstd + #[cfg_attr(backtrace_in_libstd, optimize(size))] fn new( stash: &'data Stash, object: Object<'data>, @@ -355,6 +357,8 @@ impl Cache { } // unsafe because this is required to be externally synchronized + // #[feature(optimize_attr)] is enabled when we're built inside libstd + #[cfg_attr(backtrace_in_libstd, optimize(size))] unsafe fn with_global(f: impl FnOnce(&mut Self)) { // A very small, very simple LRU cache for debug info mappings. //