I’ve made a bit of progress on this but I’m still not there.
Here’s what I want. I want to compile a safe_vault binary that does this:
$ ldd safe_vault
not a dynamic executable
“ldd” is a utility to list the dynamic libraries (runtime dependencies) of a binary.
So the binary above could be run on any Linux computer, because it has the dependencies (static libraries) included in the compile image. That’s the ideal anyway.
That binary came from a release.
If I compile the source code accompanying that release I don’t get that result. Here’s the compile process:
$ export PKG_CONFIG_ALLOW_CROSS=1
$ cargo build --release --target=x86_64-unknown-linux-musl
Notes:
- Setting the environment variable is required in order to allow the musl option to run.
- The musl option is intended to result in the standard C libraries being statically linked into the compile image.
Here’s the resulting files:
$ cd target/x86_64-unknown-linux-musl/release $ ls -la drwxr-xr-x 8 user user 4096 Jun 12 14:01 build drwxr-xr-x 2 user user 12288 Jun 12 14:07 deps drwxr-xr-x 2 user user 4096 Jun 12 14:01 examples -rw-r--r-- 1 user user 1958938 Jun 12 14:08 libsafe_vault.rlib drwxr-xr-x 2 user user 4096 Jun 12 14:01 native -rwxr-xr-x 1 user user 7140240 Jun 12 14:08 safe_vault
If I run ldd:
$ ldd safe_vault linux-vdso.so.1 (0x00007ffe8e7fc000) libsodium.so.18 => /usr/local/lib/libsodium.so.18 (0x00007f9085022000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9084e05000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9084a5a000) /lib/ld64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x00007f9085288000)
Notes:
- Libsodium is installed on this computer, and the libsodium.a static library is in the right place:
$ cd /usr/local/lib $ ls -la -rw-r--r-- 1 root staff 3940482 Jun 12 03:03 libsodium.a -rwxr-xr-x 1 root staff 899 Jun 12 03:03 libsodium.la lrwxrwxrwx 1 root staff 19 Jun 12 02:43 libsodium.so -> libsodium.so.18.1.0 lrwxrwxrwx 1 root staff 19 Jun 12 02:43 libsodium.so.18 -> libsodium.so.18.1.0 -rwxr-xr-x 1 root staff 2386272 Jun 12 02:43 libsodium.so.18.1.0
Notes:
- I’ve read @happybeing 's article on cross-compiling to ARM.
- I have tried adding an “attribute” to the toml file, as described in the Rust documentation and all I get is that stupid rlib file, but no statically-linked safe_vault binary:
#[link(name = "sodium", kind = "static")]
Any comments? What am I overlooking?