mirror of
https://github.com/hickory-dns/hickory-dns.git
synced 2026-04-25 03:05:51 +03:00
[GH-ISSUE #2207] Static build support (openssl + cross-compile) #921
Labels
No labels
blocked
breaking-change
bug
bug:critical
bug:tests
cleanup
compliance
compliance
compliance
crate:all
crate:client
crate:native-tls
crate:proto
crate:recursor
crate:resolver
crate:resolver
crate:rustls
crate:server
crate:util
dependencies
docs
duplicate
easy
easy
enhance
enhance
enhance
feature:dns-over-https
feature:dns-over-quic
feature:dns-over-tls
feature:dnsssec
feature:global_lb
feature:mdns
feature:tsig
features:edns
has workaround
ops
perf
platform:WASM
platform:android
platform:fuchsia
platform:linux
platform:macos
platform:windows
pull-request
question
test
tools
tools
trust
unclear
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hickory-dns#921
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @polarathene on GitHub (May 5, 2024).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2207
Summary
Static build support appears to be a bit broken?
While troubleshooting a bug encountered from a downstream project, I discovered it was related to
hickory-dnswhen enabling thednssec-ringfeature. During this I noticedhickory-dnsfails to succeed at producing a static build on a-gnubuild host (including when cross-compiling for a-musltarget).Reproduction
This is understandable for a glibc "static" build, but is still the same output when attempting to build for a musl target. This is only when
OPENSSL_DIRwas specified, so presumably the glibc symbols and related warnings above with the musl target are due to the build attempting to bundle/link the glibc openssl on the build host?With both
cargo buildandcargo zigbuild(without theOPENSSL_DIRENV present), the build failure for a musl target is more obvious (note:cargo zigbuildcannot perform-gnutarget static builds):Despite having the development packages required, and using the
OPENSSL_DIRor other supported ENVs from theopensslcrate documentation, these are not helpful to support cross-compiling tomusltarget. Possibly due to a long standing issue withpkg-configthat may be environment specific? 🤷♂️Reproduction environment (Docker)
If it's helpful, the above can be reproduced with docker and the following commands:
Both should be capable of building statically linked musl target.
Whereas on a musl build host to avoid cross-compiling it will be successful as it can use static libs:
Expected outcome
It should be possible to build statically, at least for cross-compiling to a musl target?
Details
System:
Version:
Crate: hickory-util
Version: v0.24.1
@polarathene commented on GitHub (May 5, 2024):
This can be resolved by adjusting the
openssldep to use thevendoredfeature, which will build OpenSSL from source:github.com/hickory-dns/hickory-dns@cffc3fac2a/Cargo.toml (L61-L63)The above reproduction environments in all three containers can then successfully build the project.
It is then possible to opt-out via
OPENSSL_NO_VENDOR=1. AFAIK, there doesn't appear to be support for opt-in via ENV, hence I don't think there is no nice workaround available? (should be possible via editing a downstream project'sCargo.tomlto override this depsopensslfeatures.. but that seems a little brittle?)As long as something in a downstream project opts in to
vendoredfeature elsewhere, it also seems to have the same effect of building vendored, so it's not a feature you can control with explicit opt-out on a crate I think? Only at build time via the mentioned opt-out ENV?I assume a potential drawback/side-effect for non-static builds is that vendoring in your own build of openssl into the binary instead of dynamically linking to openssl?
@bluejekyll commented on GitHub (May 6, 2024):
Sounds like this is specific to openssl. Do you need Openssl? We've been trying to direct people to use the ring and rustls defaults.
@polarathene commented on GitHub (May 6, 2024):
Not personally no. It was just an observation when I was trying to identify why
cargo-binstallwas failing to resolve DNS while other programs had no issue. During that troubleshooting I tried both openssl and rustls but it didn't seem specific to either AFAIK.What I did find was their
trust-dns/hickory-dnsfeature (old project name is a feature alias) was the culprit. Specifically when thehickory-dns/dnssec-ringfeature is enabled. As reported above, when I tried building this crate with that feature as a static build and with openssl (default) this failed. I looked into it and the only way for static build with openssl to work reliably across environments seems to requirevendoredto build from source, especially for cross-compilation to other targets.Despite addressing that concern, the
resolveutility was still working successfully like a dynamic linked build. I'm not sure what is different between that CLI and thecargo-binstallproject, perhaps I wasn't actually using the feature via theresolveCLI just by enabling it at build 😓I may try investigate that further to track down if the downstream failure encountered with
cargo-binstallis reproducible withresolveCLI and then if that's specific to theringcrate, but I'm not sure if I'll have the time with my inexperience across these crates.Perhaps consider switching to those as the defaults in the future? If you do not think this concern with openssl and static build support is worth addressing, no worries, I just wanted to report my findings for others to benefit 👍
Feel free to close this issue if you like :)
@bluejekyll commented on GitHub (May 18, 2024):
Thank you for spending the time on this, I appreciate that.
@PikuZheng commented on GitHub (May 20, 2024):
Since Quinn 0.11 has been released with ring 0.17, I think the factors preventing static compilation have been resolved.
@djc commented on GitHub (May 21, 2024):
Well, only after #2107 (or something like it) has been merged (see also #2206).