Skip to content

Commit 167430c

Browse files
authored
More aggressive remapping (#2442)
Looking at our strings, I noticed two things: - `/toolchain` remaps were always of the form `/toolchain/lib/rustlib/src/rust/library/core/src` - There were a bunch of strings of the form `/hubris/target/thumbv7em-none-eabihf/release/build`, which are files generated from `build.rs` scripts This PR remaps those strings more aggressively, to `/rustlib` and `/hubris/build` respectively. This saves 17920 bytes of flash on the `cosmo-b-dev` image: ``` auxflash 15936 -> 15864 control_plane_agent 114488 -> 113928 cosmo_seq 43684 -> 38304 (!) dump_agent 16860 -> 16712 fmc_demo 10312 -> 10236 hash_driver 6984 -> 6912 hf 34704 -> 34552 hiffy 22568 -> 22416 host_sp_comms 68860 -> 68484 i2c_driver 12192 -> 12156 idle 88 -> 88 ignition_flash 7488 -> 7452 jefe 9184 -> 9184 kernel 32768 -> 32768 net 74872 -> 74648 packrat 22868 -> 22800 power 34920 -> 34768 rng_driver 5800 -> 5724 sensor 8280 -> 8244 snitch 3340 -> 3340 spartan7_loader 12924 -> 12812 spd 6788 -> 6712 spi2_driver 11020 -> 10948 spi3_driver 10544 -> 10472 sprot 45252 -> 45172 sys 2720 -> 2720 thermal 21792 -> 21644 udpbroadcast 6472 -> 6400 udpecho 7008 -> 6972 udprpc 8208 -> 8172 update_server 9292 -> 9252 user_leds 1420 -> 1420 validate 7468 -> 7468 vpd 5608 -> 5608 ```
1 parent 737594c commit 167430c

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

build/xtask/src/dist.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl PackageConfig {
140140
bail!("Failed to find {:?}", board_path);
141141
}
142142

143-
let remap_paths = Self::remap_paths(&sysroot)?;
143+
let remap_paths = Self::remap_paths(&sysroot, &toml.target)?;
144144

145145
Ok(Self {
146146
app_src_dir: app_src_dir.to_path_buf(),
@@ -167,7 +167,10 @@ impl PackageConfig {
167167
self.dist_dir.join(name)
168168
}
169169

170-
fn remap_paths(sysroot: &Path) -> Result<BTreeMap<PathBuf, &'static str>> {
170+
fn remap_paths(
171+
sysroot: &Path,
172+
target: &str,
173+
) -> Result<BTreeMap<PathBuf, &'static str>> {
171174
// Panic messages in crates have a long prefix; we'll shorten it using
172175
// the --remap-path-prefix argument to reduce message size. This is
173176
// good for both binary size and for reproducibility, since we don't
@@ -210,13 +213,36 @@ impl PackageConfig {
210213
remap_paths.insert(cargo_sparse_registry, "/crates.io");
211214
}
212215

213-
remap_paths.insert(sysroot.to_path_buf(), "/toolchain");
216+
remap_paths.insert(
217+
sysroot
218+
.to_path_buf()
219+
.join("lib")
220+
.join("rustlib")
221+
.join("src")
222+
.join("rust")
223+
.join("library")
224+
.join("core")
225+
.join("src"),
226+
"/rustlib",
227+
);
214228

215229
if let Ok(dir) = std::env::var("CARGO_MANIFEST_DIR") {
216230
let mut hubris_dir = dunce::canonicalize(dir)?;
217231
hubris_dir.pop();
218232
hubris_dir.pop();
219233
remap_paths.insert(hubris_dir.to_path_buf(), "/hubris");
234+
// Shorten the build directories from
235+
// `hubris/target/thumbv7em-none-eabihf/release/build` to just
236+
// `hubris/build`
237+
remap_paths.insert(
238+
hubris_dir
239+
.to_path_buf()
240+
.join("target")
241+
.join(target)
242+
.join("release")
243+
.join("build"),
244+
"/hubris/build",
245+
);
220246
}
221247
Ok(remap_paths)
222248
}

0 commit comments

Comments
 (0)