nixpkgs/pkgs/development/compilers/tinygo/0002-Add-clang-header-path.patch
Ayke van Laethem 993efa596b
tinygo: clean up Clang header path patch
See the comment in default.nix for details. But basically, there are
only two place that needs a modification to set the correct path.

As a side effect, this makes cross compiling CGo code to Darwin work.
2023-10-12 03:32:48 +02:00

26 lines
1.4 KiB
Diff

diff --git a/builder/library.go b/builder/library.go
index 6517355b..b8de1894 100644
--- a/builder/library.go
+++ b/builder/library.go
@@ -142,7 +142,7 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
// Note: -fdebug-prefix-map is necessary to make the output archive
// reproducible. Otherwise the temporary directory is stored in the archive
// itself, which varies each run.
- args := append(l.cflags(target, headerPath), "-c", "-Oz", "-gdwarf-4", "-ffunction-sections", "-fdata-sections", "-Wno-macro-redefined", "--target="+target, "-fdebug-prefix-map="+dir+"="+remapDir)
+ args := append(l.cflags(target, headerPath), "-c", "-Oz", "-gdwarf-4", "-ffunction-sections", "-fdata-sections", "-Wno-macro-redefined", "--target="+target, "-fdebug-prefix-map="+dir+"="+remapDir, "-isystem", "@clang_include@")
cpu := config.CPU()
if cpu != "" {
// X86 has deprecated the -mcpu flag, so we need to use -march instead.
diff --git a/compileopts/config.go b/compileopts/config.go
index 39fc4f2a..8711b5a8 100644
--- a/compileopts/config.go
+++ b/compileopts/config.go
@@ -264,6 +264,7 @@ func (c *Config) CFlags() []string {
for _, flag := range c.Target.CFlags {
cflags = append(cflags, strings.ReplaceAll(flag, "{root}", goenv.Get("TINYGOROOT")))
}
+ cflags = append([]string{"-isystem", "@clang_include@"}, cflags...)
switch c.Target.Libc {
case "darwin-libSystem":
root := goenv.Get("TINYGOROOT")