-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
unix: Extend README with fully static builds section. #17456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #17456 +/- ##
=======================================
Coverage 98.54% 98.54%
=======================================
Files 169 169
Lines 21943 21943
=======================================
Hits 21623 21623
Misses 320 320 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code size report:
|
Add a new section to `ports/unix/README.md` that describes how to perform fully static builds of the MicroPython unix port. This provides clearer guidance for advanced users and CI configurations, improving documentation clarity. Fixes micropython#17399, micropython#17353 Signed-off-by: o-murphy <[email protected]>
Hi @o-murphy thank you for this MR. The documentation looks comprehensive and well-structured. Thumbs up from me :) One thing I am not sure about is the formatting of the steps - does that render well in Github? I would maybe expect using a Markdown header for each line, over bold. |
It looks like padded numeric sections for each step with the same paddings for code blocks, good I mean, but If you wish I can change it So do you want me to change #### Ensure Static Library Development Packages:
...
#### Build MicroPython with `LDFLAGS_EXTRA="-static"`:
...
#### Verification
... |
Summary
This Pull Request adds new documentation to
ports/unix/README.md
to guide users on how to build a fully statically linked MicroPython executable for the Unix port. The existing documentation forMICROPY_STANDALONE=1
only covers static linking oflibffi
. However, for deployments to minimal Linux environments (like Buildroot) or for creating truly self-contained binaries, a full static link of all dependencies (includinglibc
,libpthread
, etc.) is often required. This change addresses the common issue of binaries failing to run due to missingld.so
orlibc
mismatches in target environments.The new section, titled "Fully Static Builds (for minimal environments)", includes:
LDFLAGS_EXTRA="-static"
during the build process, including an example for cross-compilation withmipsel-linux-gnu-
.file
andldd
.Testing
Testing was performed by:
ports/unix
default configuration withLDFLAGS_EXTRA="-static"
on a Debian-based Linux system to create a fully static native executable. Verification was done usingfile
andldd
.ports/unix
withCROSS_COMPILE=mipsel-linux-gnu-
andLDFLAGS_EXTRA="-static"
on a Debian-based Linux system (withlibc6-dev-mipsel-cross
installed) to simulate a static build for an embedded Linux target. Verification was performed usingfile
and attempting to run the binary viaqemu-mipsel
.All builds successfully completed, and the resulting executables were confirmed to be statically linked.
For a practical demonstration of a successful static build, please refer to the following workflow run
Trade-offs and Alternatives
The primary trade-off for fully static builds is the increased binary size. Statically linked executables are significantly larger compared to dynamically linked ones because they embed all necessary library code directly. However, this is an acceptable trade-off for users targeting minimal environments where a dynamic linker is unavailable or incompatible, or for situations requiring a single, self-contained executable.
No direct alternatives within the current MicroPython build system were identified for achieving a full static link without passing custom
LDFLAGS
. The existingMICROPY_STANDALONE=1
flag specifically addresseslibffi
's static linking, not the entire binary's dependencies on system libraries. This documentation clarifies the existing mechanism (LDFLAGS_EXTRA
) for this specific use case.Relative issues: #17399, #17353