cargo-strip icon indicating copy to clipboard operation
cargo-strip copied to clipboard

Configure cargo-strip to have custom strip files

Open Akendo opened this issue 4 years ago • 16 comments

First of all: Thanks a lot!

The current solution implemented in #1 does not work for my configuration with MIPS. The issue is most likely that I used a custom binary to stripe down the binaries for mips. The custom strip binary is build via a SDK(OpenWrt SDK) and has a custom path in my filesystem:

~openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/bin/mips-openwrt-linux-strip ./target/mips-unknown-linux-musl/release/NetStats

Obviously, cargo stripe isn't aware of the custom, path. Hence, cargo strip requires some form of awareness about it.

Here is a suggestion: It is possible to configure within the ~/.cargo/config the binaries for the linker and archiver. That looks like this:

[target.mips-unknown-linux-musl]
ar = "~/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/bin/mips-openwrt-linux-ar"
linker = "~/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/bin/mips-openwrt-linux-gcc"

Maybe we can use the same file to configure the path to the strip binary? Something like this:

[target.mips-unknown-linux-musl]
ar = "~/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/bin/mips-openwrt-linux-ar"
linker = "~/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/bin/mips-openwrt-linux-gcc"
strip = "~/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/bin/mips-openwrt-linux-strip"

When I remember the documentation about cargo correctly, this should be than a variable at your disposable. All what we need to do is checking for the variable and test that's a valid binary.

In case you want just to a one-time execution with a custom path, it might be handy to provide the path to the specify strip binary. Just like this:

cargo strip --target=mips-unknown-linux-musl --path ~/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/bin/mips-openwrt-linux-strip

This is a lot what I'm ask for, but anyway, thanks for the tool and for the work your doing!

best regards, akendo

Akendo avatar Apr 26 '20 08:04 Akendo

It might be option build.rustflags, trying to check something running on my own.

Akendo avatar Apr 26 '20 08:04 Akendo

I think rustflags are the wrong configuration entry. Important is the [target] entry.

Akendo avatar Apr 26 '20 08:04 Akendo

In my current understanding of the documentation it seems unlikely that my purposed way is working. The documentation does not imply that my idea is working. My logic here would be that target strip should be made available via: CARGO_TARGET_<triple>_STRIP. I'm going to test for that.

Akendo avatar Apr 26 '20 08:04 Akendo

Okay it does not work:

error: expected a table, but found a string for `target.mips-unknown-linux-musl.strip` in /home/akendo/.cargo/config

I guess instead we would have to provide a patch to the upstream cargo guys to include these option OR provide with a configuration file of our own. Not sure what's the best option here.

Akendo avatar Apr 26 '20 08:04 Akendo

Thanks for your support. Could you share the strip binary from the OpenWRT SDK as well as the binary that you want to strip, or an Hello World compiled with the same toolchain?

guedou avatar Apr 26 '20 10:04 guedou

Sure how do you like to get the file?

Akendo avatar Apr 27 '20 19:04 Akendo

Could you attach them to a comment? For example after converting them to base64. otherwise, any file sharing site, like Firefox send, will do.

guedou avatar Apr 27 '20 21:04 guedou

You can download the release without a strip from here

Akendo avatar May 01 '20 09:05 Akendo

Please give me a hint once you're done downloading it. I like to remove it afterwards.

Akendo avatar May 01 '20 09:05 Akendo

Thanks. I retrieved the binary. Could you also share mips-openwrt-linux-strip?

guedou avatar May 01 '20 11:05 guedou

Sure. Wasn't thinking of that: Here. I hope that this is working out-side the sdk trunk tree.

Akendo avatar May 01 '20 12:05 Akendo

Thanks. I will investigate the binaries.

guedou avatar May 02 '20 15:05 guedou

Can you upload tjhe stripbinary again? I got the following error.

curl http://blog.akendo.eu/mips-openwrt-linux-strip
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

guedou avatar May 02 '20 15:05 guedou

Sure, one moment

Akendo avatar May 03 '20 09:05 Akendo

You have to switch from http to https.

Akendo avatar May 03 '20 09:05 Akendo

Thanks!

guedou avatar May 03 '20 10:05 guedou