-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider distributing static binaries #65
Comments
To get openssl to link statically, just don't let the build script see the dynamic libraries. I downloaded openssl-1.1.0g from here, and built them myself. Then I made a directory inside the source one called The much harder problem I've run into is getting the allocator to link properly. I get a huge pile of undefined symbols, all ending in (just remembered that openssl-sys doesn't actually build openssl. I think that's silly, but it looks like ring does?) |
I have a solution. Download the openssl-1.1.0g sources. Configure with
Can anyone confirm that this works on other machines and that the binary is actually portable? |
It worked! Thanks @saethlin . We should probably write a script that does all this (fetch openssl, unpack, compile with clang and no-async, move .a files to a dir, install toolchain, compile tiny with correct parameters). I may be busy for a few days so if anyone would want to go for it it'd be appreciated. |
@saethlin I got this working too in my Arch VM, but my binary is 16.3 MB (with --release). How do you compress it? |
Might need some work. |
@wrycode That's strange, my release binary with LTO is 7.2 MB. You can |
This doesn't seem right, on my system (Xubuntu 16.04) this method generates 4,7M binary. |
I was looking at the wrong file output, apologies. Mine was 4.9M |
FYI, if you want to do this you'll run into the situation described here: I'm applying the workaround by inserting this at the top of
|
With this I can make a statically linked executable with $ cargo build --target=x86_64-unknown-linux-musl \ --no-default-features --features tls-rustls The generated executable does not support generating desktop notifications and uses rustls instead of libssl. (#65)
With #172 we can now build tiny with rustls, so no need to statically link OpenSSL or LibreSSL. I just submitted another PR for making dbus dependency optional: #178 hides it behind a feature flag (enabled by default). Using it I can generate a statically linked executable simply by running this in
The generated executable uses rustls for TLS and does not support generating desktop notifications. |
With this I can make a statically linked executable with $ cargo build --target=x86_64-unknown-linux-musl \ --no-default-features --features tls-rustls The generated executable does not support generating desktop notifications and uses rustls instead of libssl. (#65)
This makes dbus dependency opt-in by making desktop notifications an optional feature. We also make native-tls optional and rustls the default. The idea is that `cargo build` will be easier to build because it doesn't need any system dependencies, and features that need system dependencies will be hidden behind feature flags. After this patch: (all commands in 'tiny' directory) - dbus + rustls: cargo build --features="desktop-notifications" - dbus + native-tls cargo build --features="desktop-notifications tls-native" \ --no-default-features Removing "desktop-notifications" will make a build without dbus dependency. It's now possible to make a statically-linked executable with $ cargo build --target=x86_64-unknown-linux-musl (#65)
This makes dbus dependency opt-in by making desktop notifications an optional feature. We also make native-tls optional and rustls the default. The idea is that `cargo build` will be easier to build because it doesn't need any system dependencies, and features that need system dependencies will be hidden behind feature flags. After this patch: (all commands in 'tiny' directory) - dbus + rustls: cargo build --features="desktop-notifications" - dbus + native-tls cargo build --features="desktop-notifications tls-native" \ --no-default-features Removing "desktop-notifications" will make a build without dbus dependency. It's now possible to make a statically-linked executable with $ cargo build --target=x86_64-unknown-linux-musl (#65)
This makes dbus dependency opt-in by making desktop notifications an optional feature. We also make native-tls optional and rustls the default. The idea is that `cargo build` will be easier to build because it doesn't need any system dependencies, and features that need system dependencies will be hidden behind feature flags. After this patch: (all commands in 'tiny' directory) - dbus + rustls: cargo build --features="desktop-notifications" - dbus + native-tls cargo build --features="desktop-notifications tls-native" \ --no-default-features Removing "desktop-notifications" will make a build without dbus dependency. It's now possible to make a statically-linked executable with $ cargo build --target=x86_64-unknown-linux-musl (#65)
Almost done.. only problem is ring-0.16 doesn't build on Github actions' Ubuntu 18.04 container for some reason. The error message can be seen here. I also reported this on ring's issue tracker. |
This is now implemented. When I push a new version tag the Github workflow makes tarballs for all combination of features and uploads them. See v0.5.2-test as an example. |
Per @reading123's request in #61,
I think producing static binaries is a good idea. tiny is light on dependencies (serde being the largest one) and the only culprit for Linux seems to be OpenSSL (or LibreSSL) which is required by
native_tls
. I actually managed to compile tiny usingx86_64-unknown-linux-musl
target, but (1) the binary didn't work (some kind of loader problem) (2) it still hadlibssl.so.1.1
andlibcrypto.so.1.1
as dynamic dependencies.Need to investigate further. It might help to find another Rust project that (1) generates static binaries (2) uses
native_tls
crate.The text was updated successfully, but these errors were encountered: