refactor(internal/build):remove rpath change

This commit is contained in:
luoliwoshang
2025-06-26 13:55:58 +08:00
parent f0728c4fe0
commit e60c3bd943
3 changed files with 3 additions and 41 deletions

View File

@@ -251,7 +251,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
os.Setenv("PATH", env.BinDir()+":"+os.Getenv("PATH")) // TODO(xsw): check windows os.Setenv("PATH", env.BinDir()+":"+os.Getenv("PATH")) // TODO(xsw): check windows
output := conf.OutFile != "" output := conf.OutFile != ""
export, err := crosscompile.Use(conf.Goos, conf.Goarch, IsWasiThreadsEnabled(), IsRpathChangeEnabled()) export, err := crosscompile.Use(conf.Goos, conf.Goarch, IsWasiThreadsEnabled())
check(err) check(err)
ctx := &context{env: env, conf: cfg, progSSA: progSSA, prog: prog, dedup: dedup, ctx := &context{env: env, conf: cfg, progSSA: progSSA, prog: prog, dedup: dedup,
patches: patches, built: make(map[string]none), initial: initial, mode: mode, patches: patches, built: make(map[string]none), initial: initial, mode: mode,
@@ -568,35 +568,9 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, global l
llFiles = append(llFiles, export) llFiles = append(llFiles, export)
} }
// add rpath and find libs
exargs := make([]string, 0, ctx.nLibdir<<1)
libs := make([]string, 0, ctx.nLibdir*3)
if IsRpathChangeEnabled() {
for _, arg := range linkArgs {
if strings.HasPrefix(arg, "-L") {
exargs = append(exargs, "-rpath", arg[2:])
} else if strings.HasPrefix(arg, "-l") {
libs = append(libs, arg[2:])
}
}
}
linkArgs = append(linkArgs, exargs...)
err = compileAndLinkLLFiles(ctx, app, llFiles, linkArgs, verbose) err = compileAndLinkLLFiles(ctx, app, llFiles, linkArgs, verbose)
check(err) check(err)
if IsRpathChangeEnabled() && ctx.buildConf.Goos == "darwin" {
dylibDeps := make([]string, 0, len(libs))
for _, lib := range libs {
dylibDep := findDylibDep(app, lib)
if dylibDep != "" {
dylibDeps = append(dylibDeps, dylibDep)
}
}
err := ctx.env.InstallNameTool().ChangeToRpath(app, dylibDeps...)
check(err)
}
switch mode { switch mode {
case ModeTest: case ModeTest:
cmd := exec.Command(app, conf.RunArgs...) cmd := exec.Command(app, conf.RunArgs...)
@@ -971,7 +945,6 @@ const llgoDbgSyms = "LLGO_DEBUG_SYMBOLS"
const llgoTrace = "LLGO_TRACE" const llgoTrace = "LLGO_TRACE"
const llgoOptimize = "LLGO_OPTIMIZE" const llgoOptimize = "LLGO_OPTIMIZE"
const llgoCheck = "LLGO_CHECK" const llgoCheck = "LLGO_CHECK"
const llgoRpathChange = "LLGO_RPATH_CHANGE"
const llgoWasmRuntime = "LLGO_WASM_RUNTIME" const llgoWasmRuntime = "LLGO_WASM_RUNTIME"
const llgoWasiThreads = "LLGO_WASI_THREADS" const llgoWasiThreads = "LLGO_WASI_THREADS"
const llgoStdioNobuf = "LLGO_STDIO_NOBUF" const llgoStdioNobuf = "LLGO_STDIO_NOBUF"
@@ -1018,10 +991,6 @@ func IsCheckEnable() bool {
return isEnvOn(llgoCheck, false) return isEnvOn(llgoCheck, false)
} }
func IsRpathChangeEnabled() bool {
return isEnvOn(llgoRpathChange, false)
}
func IsWasiThreadsEnabled() bool { func IsWasiThreadsEnabled() bool {
return isEnvOn(llgoWasiThreads, true) return isEnvOn(llgoWasiThreads, true)
} }

View File

@@ -25,7 +25,7 @@ func cacheDir() string {
return filepath.Join(env.LLGoCacheDir(), "crosscompile") return filepath.Join(env.LLGoCacheDir(), "crosscompile")
} }
func Use(goos, goarch string, wasiThreads, changeRpath bool) (export Export, err error) { func Use(goos, goarch string, wasiThreads bool) (export Export, err error) {
targetTriple := llvm.GetTargetTriple(goos, goarch) targetTriple := llvm.GetTargetTriple(goos, goarch)
if runtime.GOOS == goos && runtime.GOARCH == goarch { if runtime.GOOS == goos && runtime.GOARCH == goarch {
@@ -41,13 +41,6 @@ func Use(goos, goarch string, wasiThreads, changeRpath bool) (export Export, err
// Add OS-specific flags // Add OS-specific flags
switch goos { switch goos {
case "darwin": // ld64.lld (macOS) case "darwin": // ld64.lld (macOS)
if changeRpath {
export.LDFLAGS = append(
export.LDFLAGS,
"-rpath", "@loader_path",
"-rpath", "@loader_path/../lib",
)
}
export.LDFLAGS = append( export.LDFLAGS = append(
export.LDFLAGS, export.LDFLAGS,
"-Xlinker", "-dead_strip", "-Xlinker", "-dead_strip",

View File

@@ -75,7 +75,7 @@ func TestUseCrossCompileSDK(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
export, err := Use(tc.goos, tc.goarch, false, false) export, err := Use(tc.goos, tc.goarch, false)
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)