emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
22.5k stars 1.61k forks source link

Static Binaries #2144

Open TheDarkula opened 2 years ago

TheDarkula commented 2 years ago

First off, thank you for all of your work!

I had a look at issue #339.

I am presuming that things have changed with egui's dependencies, because ldd shows that the binaries are dynamic:

linux-vdso.so.1 (0x00007fff6adfe000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007f991c3cf000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x00007f991c37f000)
libexpat.so.1 => /usr/lib/libexpat.so.1 (0x00007f991c354000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f991c334000)
libm.so.6 => /usr/lib/libm.so.6 (0x00007f991b118000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007f991af31000)
/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f991c4e7000)
libz.so.1 => /usr/lib/libz.so.1 (0x00007f991c318000)
libbz2.so.1.0 => /usr/lib/libbz2.so.1.0 (0x00007f991c305000)
libpng16.so.16 => /usr/lib/libpng16.so.16 (0x00007f991aef8000)
libharfbuzz.so.0 => /usr/lib/libharfbuzz.so.0 (0x00007f991ae0d000)
libbrotlidec.so.1 => /usr/lib/libbrotlidec.so.1 (0x00007f991adff000)
libgraphite2.so.3 => /usr/lib/libgraphite2.so.3 (0x00007f991addd000)
libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007f991aca0000)
libbrotlicommon.so.1 => /usr/lib/libbrotlicommon.so.1 (0x00007f991ac7d000)
libpcre2-8.so.0 => /usr/lib/libpcre2-8.so.0 (0x00007f991abe2000)

I tried compiling with cross using: env RUST_FONTCONFIG_DLOPEN=on cross build --target x86_64-unknown-linux-musl

I have a Cross.toml with the following contents:

[target.x86_64-unknown-linux-musl.env]
passthrough = ["RUST_FONTCONFIG_DLOPEN"]

I tried with RUST_FONTCONFIG_DLOPEN=on, as suggested here.

Cross outputs these errors:

--- stderr
  thread 'main' panicked at '`"pkg-config" "--libs" "--cflags" "fontconfig" "fontconfig >= 2.11.1"` did not exit successfully: exit status: 1
  error: could not find system library 'fontconfig' required by the 'servo-fontconfig-sys' crate

  --- stderr
  Package fontconfig was not found in the pkg-config search path.
  Perhaps you should add the directory containing `fontconfig.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'fontconfig' found
  Package fontconfig was not found in the pkg-config search path.
  Perhaps you should add the directory containing `fontconfig.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'fontconfig' found
  ', /cargo/registry/src/github.com-1ecc6299db9ec823/servo-fontconfig-sys-5.1.0/build.rs:34:17

Something similar, but not really helpful is this issue

Is there something obvious I am missing to get a static binary?

RegenJacob commented 2 years ago

linux-vdso.so.1 (0x00007fff6adfe000) libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007f991c3cf000) libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x00007f991c37f000) libexpat.so.1 => /usr/lib/libexpat.so.1 (0x00007f991c354000) libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f991c334000) libm.so.6 => /usr/lib/libm.so.6 (0x00007f991b118000) libc.so.6 => /usr/lib/libc.so.6 (0x00007f991af31000) /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f991c4e7000) libz.so.1 => /usr/lib/libz.so.1 (0x00007f991c318000) libbz2.so.1.0 => /usr/lib/libbz2.so.1.0 (0x00007f991c305000) libpng16.so.16 => /usr/lib/libpng16.so.16 (0x00007f991aef8000) libharfbuzz.so.0 => /usr/lib/libharfbuzz.so.0 (0x00007f991ae0d000) libbrotlidec.so.1 => /usr/lib/libbrotlidec.so.1 (0x00007f991adff000) libgraphite2.so.3 => /usr/lib/libgraphite2.so.3 (0x00007f991addd000) libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007f991aca0000) libbrotlicommon.so.1 => /usr/lib/libbrotlicommon.so.1 (0x00007f991ac7d000) libpcre2-8.so.0 => /usr/lib/libpcre2-8.so.0 (0x00007f991abe2000)

most of those are gnu / rendering libs used by eframe. with dynamic linking in rust the dependencies you specify in Cargo.toml are meant those are statically linked but if one of those needs external dependencies they have to be installed on the system

TheDarkula commented 2 years ago

@RegenJacob I understand, however, it is failing when trying to link the fontconfig-sys crate. In their documentation, they have this:

Alternatively, set the environment variable RUST_FONTCONFIG_DLOPEN=on or enable the dlopen Cargo feature to load the library at runtime rather than link at build time (useful for cross compiling).

That is why I tried running a build with RUST_FONTCONFIG_DLOPEN=on set, which should not actually try to link the library at build time, but it still is.

RegenJacob commented 2 years ago

this might help: https://github.com/rust-windowing/winit/issues/1818#issuecomment-903765478