Skip to content

Commit 9f38338

Browse files
authored
Merge pull request #1032 from cpunion/fix-linking
Remove LLVM runtime depencendy, better c toolchain integration
2 parents 2c417d7 + 8c76436 commit 9f38338

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

.github/workflows/doc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
id: lychee
2828
uses: lycheeverse/lychee-action@v2
2929
with:
30-
args: README.md
30+
args: --max-concurrency 3 --retry-wait-time 15 README.md
3131

3232
remote_install:
3333
strategy:

c/debug/debug.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
)
1212

1313
const (
14-
LLGoPackage = "link: $(llvm-config --ldflags --libs); -lunwind"
15-
LLGoFiles = "$(llvm-config --cflags): _wrap/debug.c"
14+
LLGoPackage = "link"
15+
LLGoFiles = "_wrap/debug.c"
1616
)
1717

1818
type Info struct {

compiler/internal/build/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, linkArgs
488488
if verbose {
489489
fmt.Fprintln(os.Stderr, "clang", args)
490490
}
491-
err = ctx.env.Clang().Exec(args...)
491+
err = ctx.env.Clang().Link(args...)
492492
check(err)
493493

494494
if IsRpathChangeEnabled() && runtime.GOOS == "darwin" {
@@ -870,7 +870,7 @@ func clFile(ctx *context, args []string, cFile, expFile string, procFile func(li
870870
if verbose {
871871
fmt.Fprintln(os.Stderr, "clang", args)
872872
}
873-
err := ctx.env.Clang().Exec(args...)
873+
err := ctx.env.Clang().Compile(args...)
874874
check(err)
875875
procFile(llFile)
876876
}

runtime/internal/clite/debug/debug.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
)
1212

1313
const (
14-
LLGoPackage = "link: $(llvm-config --ldflags --libs); -lunwind"
15-
LLGoFiles = "$(llvm-config --cflags): _wrap/debug.c"
14+
LLGoPackage = "link"
15+
LLGoFiles = "_wrap/debug.c"
1616
)
1717

1818
type Info struct {

xtool/clang/clang.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"io"
2121
"os"
2222
"os/exec"
23+
"strings"
2324
)
2425

2526
// -----------------------------------------------------------------------------
@@ -40,6 +41,32 @@ func New(app string) *Cmd {
4041
return &Cmd{app, os.Stdout, os.Stderr}
4142
}
4243

44+
func (p *Cmd) Compile(args ...string) error {
45+
// Parse CFLAGS environment variable into separate arguments
46+
cflags := strings.Fields(os.Getenv("CFLAGS"))
47+
if len(cflags) > 0 {
48+
// Create a new slice with capacity for all arguments
49+
newArgs := make([]string, 0, len(cflags)+len(args))
50+
newArgs = append(newArgs, cflags...)
51+
newArgs = append(newArgs, args...)
52+
args = newArgs
53+
}
54+
return p.Exec(args...)
55+
}
56+
57+
func (p *Cmd) Link(args ...string) error {
58+
// Parse LDFLAGS environment variable into separate arguments
59+
ldflags := strings.Fields(os.Getenv("LDFLAGS"))
60+
if len(ldflags) > 0 {
61+
// Create a new slice with capacity for all arguments
62+
newArgs := make([]string, 0, len(ldflags)+len(args))
63+
newArgs = append(newArgs, ldflags...)
64+
newArgs = append(newArgs, args...)
65+
args = newArgs
66+
}
67+
return p.Exec(args...)
68+
}
69+
4370
// Exec executes a clang command.
4471
func (p *Cmd) Exec(args ...string) error {
4572
cmd := exec.Command(p.app, args...)

0 commit comments

Comments
 (0)