-
Notifications
You must be signed in to change notification settings - Fork 49
build: prepare the LLVM 21 upgrade #2334
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: main
Are you sure you want to change the base?
Changes from all commits
e74c37b
2e10271
bf6d6ef
e911323
29eb130
dc4aa1a
152cb88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ import ( | |
| "github.com/xgo-dev/llgo/internal/typepatch" | ||
| "github.com/xgo-dev/llgo/ssa/abi" | ||
| xenv "github.com/xgo-dev/llgo/xtool/env" | ||
| envllvm "github.com/xgo-dev/llgo/xtool/env/llvm" | ||
| gllvm "github.com/xgo-dev/llvm" | ||
|
|
||
| llruntime "github.com/xgo-dev/llgo/runtime" | ||
|
|
@@ -411,6 +412,9 @@ func Build(inv Invocation) ([]Package, error) { | |
| if err != nil { | ||
| return nil, fmt.Errorf("failed to setup crosscompile: %w", err) | ||
| } | ||
| if err := validateLLVMToolchain(export); err != nil { | ||
| return nil, fmt.Errorf("invalid LLVM toolchain: %w", err) | ||
| } | ||
| applyBuildModeCompileFlags(conf.BuildMode, &export) | ||
| // Update GOOS/GOARCH from export if target was used | ||
| if conf.Target != "" && export.GOOS != "" { | ||
|
|
@@ -799,6 +803,22 @@ func Build(inv Invocation) ([]Package, error) { | |
| return allPkgs, nil | ||
| } | ||
|
|
||
| func validateLLVMToolchain(export crosscompile.Export) error { | ||
| if export.ClangRoot != "" { | ||
| binDir := filepath.Join(export.ClangRoot, "bin") | ||
| return envllvm.ValidateToolchainMajor(gllvm.Version, | ||
| filepath.Join(binDir, "llvm-config"), | ||
| filepath.Join(binDir, "clang"), | ||
| filepath.Join(binDir, "ld.lld"), | ||
|
Comment on lines
+806
to
+812
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] Toolchain validator hardcodes ld.lld/clang (breaks darwin/windows)
Also, the |
||
| ) | ||
| } | ||
| compiler := filepath.Base(export.CC) | ||
| if compiler != "clang" && compiler != "clang++" { | ||
| return nil | ||
| } | ||
| return envllvm.ValidateToolchainMajor(gllvm.Version, "llvm-config", export.CC, "ld.lld") | ||
| } | ||
|
|
||
| // cHeaderPackages excludes the patched standard runtime implementation. Its | ||
| // //export callbacks are linker implementation details and may use internal C | ||
| // types that are deliberately not representable in a public generated header. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] validateLLVMToolchain runs 3 uncached --version subprocesses on every Build
Buildnow unconditionally callsvalidateLLVMToolchain, which spawns three subprocesses (llvm-config,clang/export.CC,ld.lld) viaexec.Command(tool, "--version"). For a one-shotllgo buildthis is negligible. But in-process, high-fan-out drivers (thecltestharness,go testsuites that callBuild/Doonce per package) will spawn hundreds x 3--versionprocesses per run, all producing the same answer sincegllvm.Versionand the toolchain paths are constant for the process lifetime. Consider memoizing the result per(linkedVersion, toolPath)inValidateToolchainMajorso repeatedBuildcalls pay the cost once.