Lessons Learned: Building statically-linked Rust binaries (OpenSSL) – David Vass...
source link: https://blog.davidvassallo.me/2021/06/10/lessons-learned-building-statically-linked-rust-binaries-openssl/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Lessons Learned: Building statically-linked Rust binaries (OpenSSL)
In a couple of modules which used in CyberSift, Rust is slowly making an appearance, depending on the use-case at hand. Generally we develop in GoLang, and one of the advantages was the resulting binary, which pretty much ran anywhere as long as the right architecture and OS are used. We could develop on Ubuntu, and run in CentOS without any issues.
By default however, Rust isn’t quite the same. Rust compiles to dynamically-linked binaries… meaning the resulting executable expects to find certain shared libraries accessible. If your project includes some crates like OpenSSL, moving the default resulting executable from Ubuntu to CentOS will cause “missing library” errors at runtime. The solution is to configure the Rust compiler to output static binaries. The procedure is very well documented here:
In a nutshell:
### Compile static binary using rust
# 1. Update rustup
rustup update
# 2. Add some MUSL dependencies
sudo apt-get install pkg-config musl-tools
# 3. Add the Linux MUSL toolchain
rustup target add x86_64-unknown-linux-musl`-
Running the above gets you most of the way there, but still gives compilation errors if your project contains OpenSSL crates. The solution is two fold: at the OS level and at Rust level.
@ OS Level : Install OpenSSL development packages
In a (Ubuntu) command prompt:
sudo apt-get install libssl-dev
@ Rust Level : Ensure to use the OpenSSL “vendored” feature
In your Cargo.toml file:
[dependencies]
# ...
openssl = { version = "*", features = ["vendored"] } #https://docs.rs/openssl/0.10.34/openssl/#vendored
And you should be good to go to produce a Rust compiled static binary including OpenSSL with:
cargo build --target x86_64-unknown-linux-musl --release
Related
Recommend
-
46
writeup.ai is an open-sourced text-bot that writes with you. It's (mostly) powered by OpenAI's
-
35
One of my recent side projects was building an automated trading system for the crypto markets. To be fair, I probably spent more time on this than on my full-time job, so calling it a side project may not be completely...
-
12
-
6
Lessons Learned Building a Backend-as-a-Service: A Technical Deep DiveIn this post we share our technical learnings from building a multi-tenant Backend-as-a-Service (BaaS). We cover how a BaaS works, how it fit...
-
14
Lessons Learned from Building the YARP Proxy on .NET3,333 views•Nov 13, 2020 YARP is an open so...
-
7
6 lessons learned when building complex productsZahra Sedaghat08.12.21Tackling complexities of highly regulated, nuanced applications Healthcare...
-
5
ReverseSSH A statically-linked ssh server with a reverse connection feature for simple yet powerful remote access. Most useful during HackTheBox challenges, CTFs or similar. Has been developed and was extensiv...
-
7
Soupault 4.0.0: as extensible as Jekyll, still statically linked Estimated reading time: 12 minutes. Date: 2022-05-14 ...
-
4
oasis oasis is a small linux system. It is probably quite a bit different from other Linux-based operating systems you might be familiar with, and is probably better compared to a BSD. There are many features that distinguis...
-
5
Force all native libraries to be statically linked when linking a static binary by Amanieu · Pull Request #111698 · rust-lang/rust · GitHub
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK