Comments (7)
I am able to get rid of all path and dependencies information by adding trim-paths = "all"
to [profile.release]
.
Now the official RFC doc mentioned this option.
from min-sized-rust.
Thank you @johnthagen, I will check these out!
Also, I was looking through the Unstable Book and found these--any thoughts if they are helpful too? On quick look, looks like perhaps the -Ztrim-paths
is related to these. I really appreciate you chiming in on this thread. I'll read the links you provided and close with findings if it addresses my issue.
from min-sized-rust.
This won't help for size, but a short term idea to help avoid leaking your personal information into the binaries would be to build in a container (for Linux builds) or some kind of generic CI system or VM for Windows/macOS such as GitHub Actions.
from min-sized-rust.
For reproduction, there is this example (which began the discussion that led to -Z trim-paths
):
[dependencies]
rand = "0.8.0"
use rand::prelude::*;
fn main() {
let r: f64 = rand::thread_rng().gen();
println!("{}", r);
}
Then with either the mentioned -Z trim-paths
or RUSTFLAGS -Z location-detail=none
the home user is not present in the strings
output:
$ cargo +nightly build --release -Z trim-paths
$ RUSTFLAGS="-Z location-detail=none" cargo +nightly build --release
- I confirmed it did contain my user home path without either of those options (with or without your
Cargo.toml
release additons). - I built this reproduction:
- With a fresh project created via
cargo init
+ applying the above change snippets. - With the current nightly for Rust.
- On Windows WSL2 x86_64 with the
x86_64-unknown-linux-gnu
target & toolchain.
- With a fresh project created via
Perhaps you can verify the above, and then try identify what is being done differently for those not to work. Make sure you're not building from any cache which may already have those paths too?
There is also this issue which notes that RUSTFLAGS
will apply differently when an explicit --target
is set. I could be misunderstanding that though, may only be relevant when using -C target-feature
to override a target default. Still it highlights a gotcha where config compiled differently (the fix for the user was to provide the explicit --target
).
TL;DR
Maybe try -Z location-detail=none
(RUSTFLAG
env, not cargo
option), since it seems to achieve the same? (at least in the reproduction example, I assume it's a more aggressive approach with other side-effects)
from min-sized-rust.
You may be interested in this:
Specifically -Ztrim-paths
from min-sized-rust.
Ran with -Ztrim-paths
on current nightly but the local paths are still in there. I'm probably doing something wrong with it and will keep working at it.
from min-sized-rust.
From https://rust-lang.github.io/rfcs/3127-trim-paths.html#cargo:
It is defaulted to
none
for debug profiles, andobject
for release profiles
The default release profile setting (object) sanitises only the paths in emitted executable or library files. It always affects paths from macros such as panic messages, and in debug information only if they will be embedded together with the binary (the default on platforms with ELF binaries, such as Linux and windows-gnu), but will not touch them if they are in separate files (the default on Windows MSVC and macOS). But the paths to these separate files are sanitised.
Reading the docs, it seems like this default for release profile should resolve most practical issues related to privacy. So when this goes stable, trimming paths should just work for everyone. Also seems like if you are using nightly
, you can already get this behavior by default.
For reference, as of Rust 1.75.0, this is still a nightly-only feature.
from min-sized-rust.
Related Issues (20)
- Add note about monomorphisation HOT 6
- How to min size on windows? HOT 8
- Unable to strip information HOT 3
- Update strip documentation for upcoming stable Cargo release
- Custom ld script HOT 4
- Identical code folding HOT 2
- Mention stripping additional sections to slightly reduce binary size HOT 2
- Port away from actions-rs CI action
- Using syscalls and ld script HOT 5
- Add note about cross compiling via nightly HOT 2
- Add a reference to "A very small Rust binary indeed" HOT 1
- cargo-unused-features HOT 1
- Feature request: Show effectiveness of each step HOT 11
- libc build failure on macos-12 and Rust 1.28 & 1.30
- `rust-musl-builder` is currently unmaintained HOT 1
- -Zlocation-detail=none HOT 2
- min sized -lib (.a)
- Is there no way to use --gc-sections in rust? HOT 4
- Strip is now default HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from min-sized-rust.