indygreg / PyOxidizer

A modern Python application packaging and distribution tool
Mozilla Public License 2.0
5.47k stars 238 forks source link

musl static compilation of PyOxidizer #116

Open Hack-Hut opened 5 years ago

Hack-Hut commented 5 years ago

I would like to compile a statically linked version of PyOxidizer with musl instead of glibc. I read in your documentation the following.

"On Linux, a binary built with musl libc should just work on pretty much any Linux machine."

And that you can build said binary with the following.

"pyoxidizer build --target x86_64-unknown-linux-musl"

I want to be able to do this, but my compilation machine has no access to the internet and will not be able to to download the dependencies. So the following, will not work.

Or by cloning the Git repository and building the project locally: "$ git clone https://github.com/indygreg/PyOxidizer.git $ cd PyOxidizer $ cargo install --path pyoxidizer"

This means that I cannot install PyOxidizer. I would like to pre-compile a version of PyOxidizer on a machine at home with internet with musl so that I can import it into the offline machine.

I have tried the following:

sudo apt-get install musl-tools pkg-config libssl-dev 
rustup target add x86_64-unknown-linux-musl 
export PKG_CONFIG_ALLOW_CROSS=1
cargo install pyoxidizer --target x86_64-unknown-linux-musl  --force

Giving me the following error.

`Error: failed to run custom build command for `openssl-sys v0.9.48`

Caused by:
  process didn't exit successfully: `/tmp/cargo-installeHZ2b4/release/build/openssl-sys-c6ab3905e6834642/build-script-main` (exit code: 101)
--- stdout
cargo:rustc-cfg=const_fn
cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR
X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR unset
cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
OPENSSL_LIB_DIR unset
cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_INCLUDE_DIR
X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_INCLUDE_DIR unset
cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
OPENSSL_INCLUDE_DIR unset
cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR
X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR unset
cargo:rerun-if-env-changed=OPENSSL_DIR
OPENSSL_DIR unset
cargo:rustc-link-lib=ssl
cargo:rustc-link-lib=crypto
OPT_LEVEL = Some("3")
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-unknown-linux-gnu")
CC_x86_64-unknown-linux-musl = None
CC_x86_64_unknown_linux_musl = None
TARGET_CC = None
CC = None
CROSS_COMPILE = None
CFLAGS_x86_64-unknown-linux-musl = None
CFLAGS_x86_64_unknown_linux_musl = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("crt-static,fxsr,sse,sse2")
running: "musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-static" "-Wall" "-Wextra" "-E" "build/expando.c"
cargo:warning=build/expando.c:1:10: fatal error: openssl/opensslv.h: No such file or directory
cargo:warning= #include <openssl/opensslv.h>
cargo:warning=          ^~~~~~~~~~~~~~~~~~~~
cargo:warning=compilation terminated.
exit code: 1

--- stderr
thread 'main' panicked at '
Header expansion error:
Error { kind: ToolExecError, message: "Command \"musl-gcc\" \"-O3\" \"-ffunction-sections\" \"-fdata-sections\" \"-fPIC\" \"-m64\" \"-static\" \"-Wall\" \"-Wextra\" \"-E\" \"build/expando.c\" with args \"musl-gcc\" did not execute successfully (status code exit code: 1)." }

Failed to find OpenSSL development headers.

I know that this is probably not an issue with PyOxidizer, but there is a small audience out there that could really use relocatable PyOxidizer binary. I really do think this project is great.

jayvdb commented 5 years ago

my compilation machine has no access to the internet and will not be able to to download the dependencies.

This appears to be the core problem, and I suspect that it has a large audience. The musl part of the description is a bit misleading about what the problem is, IMO.

If I was packaging PyOxidizer for a distro, I would need to pre-fetch all of the resources it needs so that the built package was complete, and able to be tested in an isolated VM without network access.

Also when I create two projects with an identical target platform, the prebuilt cpython tarball is fetched twice, and cached inside of the project, rather than in some common area so that it can be re-used.

indygreg commented 5 years ago

I think the request here is for a pre-built distribution of PyOxidizer that can be easily installed. This will come in time.

But I doubt PyOxidizer will ever bundle a full Python distribution with itself: that is something you will need to download from the Internet. Same for all the Rust dependencies. And the Python applications you compile.

Maybe things will change eventually. But supporting machines without Internet connectivity is not a high priority for me because I suspect not many people have that constraint. There are far more important things to work on first.

dufferzafar commented 2 years ago

@indygreg Do you think it'd make sense to have pre-built binaries of PyOxy linked with musl instead of glibc?

I want to run python3.10 scripts on boxes that have very old GLIBC.