4 ms·
You can use Bazel to build a self-contained Python binary that bundles the interpreter and all its dependencies by using a py_runtime rule[1]. It's fairly strai
by alexhutcheson 6y ago
You can use Bazel to build a self-contained Python binary that bundles the interpreter and all its dependencies by using a py_runtime rule[1]. It's fairly straightforward and doesn't require much Bazel knowledge - there are simple examples on GitHub[2].
There are a couple other tools that take the same approach, including PyOxidizer[3], which was written by a Mercurial maintainer.
[1] https://docs.bazel.build/versions/master/be/python.html#py_runtime https://docs.bazel.build/versions/master/be/python.html#py_r...
[2] https://github.com/erain/bazel-python-example https://github.com/erain/bazel-python-example
[3] https://pyoxidizer.readthedocs.io/en/stable/overview.html https://pyoxidizer.readthedocs.io/en/stable/overview.html
- ed25519FUUU 6y agoCan you really make it self contained? For example, does the host need a tz package? What about libssl or libcrypto? As far as I know the only language making static binaries easily is Go, but it was a first class language design principle. For everybody else it’s a jenky 1000 line Makefile. And don’t get me started on cross-compiling!
- toby 6y agoRust?
- ed25519FUUU 6y agoRust can definitely do it, but there still are a lot of gotchas. Many languages can do it, but there are so many pitfalls. For example, a host tz package.
- jzoch 6y agoI would argue rust does it much better than go. When you have to resort to hacks like cgo that subtly change the performance and functional characteristics of your program i wouldnt call it "first class". Its good, dont get me wrong, I like how go cross-compiles most things. I wouldn't say its the gold-standard as long as cgo continues to be a thing Edit: I mention cgo as many who want to cross-compile a statically linked binary may want to interface with other libs via FFI and this is a huge gotcha. It is a bit tangential to strict "static linking binary building".
- thethimble 6y ago> Binaries produced with PyOxidizer are highly portable and can work on nearly every system without any special requirements like containers, FUSE filesystems, or even temporary directory access. On Linux, PyOxidizer can produce executables that are fully statically linked and don’t even support dynamic loading. https://pyoxidizer.readthedocs.io/en/stable/overview.html https://pyoxidizer.readthedocs.io/en/stable/overview.html
- slaman 6y agoI've found PyOxidizer immature in comparison to pyInstaller. https://www.pyinstaller.org/ https://www.pyinstaller.org/ Your milage might vary, but I think the former is still very much a work in progress.
- cbarrick 6y ago> As far as I know the only language making static binaries easily is Go, but it was a first class language design principle. Rust does this as well. The official high level build tool, `cargo`, uses a declarative TOML file for dependency management and supports lock files for deterministic builds. The default output is a single, statically linked binary. Rust does depend on libc (like Go) which brings in dynamic linking on some platforms. But Cargo supports easy cross-compilation, and the `x86_64-unknown-linux-musl` target will produce a fully static binary.
- tastyminerals 6y agoD, Rust -- just what first springs to mind.
- cle 6y agoIt can statically link Linux executables, including musl libc, libssl, libcrypto, and other libs that are usually dynamically linked. It can't do this for non-Linux executables (e.g. Windows, Mac). On those OSs, the executables are dynamically linked with system libraries.
- dnautics 6y agoSo now as a developer you want me to install the jvm first, before even installing python?
- alexhutcheson 6y agoBazel bundles a private Java runtime, so you don’t need to install the JDK unless you plan to compile Java code: https://docs.bazel.build/versions/master/install.html https://docs.bazel.build/versions/master/install.html