feat(build): support crosscompile - #166
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
/review |
There was a problem hiding this comment.
Review: cross-compile target support
Solid, well-tested feature (strong error-path/darwin/linux/gnu-musl coverage, defensive slice copies in the toolchain accessors). One issue is a potential process deadlock and should be addressed before merge; the rest are correctness/robustness and maintainability notes. Non-blocking review.
Highlights
- Critical: the new target middleware
panics for recoverable errors, and the execbroker holds a non-deferredRLockacross the middleware call — a panic leaks the read lock and deadlocks the process. See inline comments oninternal/execbroker/execbroker.go,internal/crosscompile/c/target.go, andinternal/crosscompile/crosscompile.go. - Important: a partial
--os/--archmatrix is misclassified as cross-compile (cmd/llar/internal/make.go).
Minor / maintainability (not inlined)
internal/crosscompile/crosscompile.go(customTargetdoc comment, ~lines 33-35): "customTarget uses the bootstrap toolchain to build libc itself" is inaccurate —LoadreturnsbootstrapTargetwhenroot.Path == cSysroot.Path, socustomTargetactually builds a consumer against a Formula-supplied libc, not libc itself. Suggest rewording.internal/crosscompile/c/toolchain.go(lines 27-33): exported accessorsCC()/CXX()/Linker()/Archiver()/Ranlib()/NM()/Strip()lack doc comments while every other exported symbol in the package has one;revive/golintwill flag this.internal/crosscompile/c/target.go(autotoolsPatch): the--hostdetection re-reads and scans theconfigurescript on every autotools command. The result is deterministic per target and could be cached alongsidetempDir/toolchainFile. Low impact.- Latent concurrency: both
Usemethods lazily initialize shared fields (toolchainFile/tempDir,configured) without synchronization. Safe today because builds run sequentially, butbuild.gocarries a// TODO(MeteorsLiu): Parallel buildnote — worth a comment documenting the assumption or async.Onceguard.
Findings without inline locations
internal/execbroker/execbroker.go:149:scopeMu.RUnlock()here is not deferred, andscope.Middleware(req)(line 146) is called inside the locked region. The new C-target middleware canpanic(seecrosscompile.goandc/target.goUsemethods), and a panic unwinds past this line, leaking the read lock permanently and deadlocking the nextscopeMu.Lock(). Recommenddefer scopeMu.RUnlock()(or arecover) so the lock is always released, in addition to fixing the middleware to not panic.
e1fcd6f to
49947d0
Compare
49947d0 to
50b603b
Compare
luoliwoshang
left a comment
There was a problem hiding this comment.
这里之前在LLGo构建发布时碰到一些交叉构建的问题:https://github.com/xgo-dev/llgo/blob/main/.github/actions/setup-goreleaser/action.yml。
这里会提前准备一整个linux环境,包括所有/usr/lib,/usr/include,用来构建LLGo,其实是因为会依赖一些 build-essential zlib1g-dev工具,在我们这里,有必要准备一个类似的方案么,即扣出一个稍微完整的环境进行构建
| - name: Prepare macOS 14.5 SDK | ||
| run: | | ||
| archive="$RUNNER_TEMP/MacOSX14.5.sdk.tar.xz" | ||
| curl --fail --location --retry 3 \ | ||
| "https://github.com/joseluisq/macosx-sdks/releases/download/14.5/MacOSX14.5.sdk.tar.xz" \ | ||
| --output "$archive" | ||
| echo "6e146275d19f027faa2e8354da5e0267513abf013b8f16ad65a231653a2b1c5d $archive" | sha256sum --check |
There was a problem hiding this comment.
经过我们上次讨论,其实这部分应该会是llar交叉构建时的逻辑
This PR adds cross-compilation support to the LLAR build pipeline for C libraries.
The implementation includes:
execbroker, CMake, and Autotools builds.pkgconfig.Use, preserve missing optional pkg-config directories, and handle the result in Go and Formula callers.The design is documented at https://github.com/xgo-dev/llar/wiki/Cross-compile-Design. This keeps target behavior centralized while allowing existing Formulas to use the same build-system APIs.