Merge pull request #260454 from aykevl/tinygo-clang-headers

tinygo: clean up Clang header path patch

authored by maxine and committed by GitHub 00ee862b fa14c198

+33 -46
+22 -43
pkgs/development/compilers/tinygo/0002-Add-clang-header-path.patch
··· 1 - diff --git a/builder/builtins.go b/builder/builtins.go 2 - index a1066b67..f4f8ca79 100644 3 - --- a/builder/builtins.go 4 - +++ b/builder/builtins.go 5 - @@ -179,7 +179,7 @@ var avrBuiltins = []string{ 6 - var CompilerRT = Library{ 7 - name: "compiler-rt", 8 - cflags: func(target, headerPath string) []string { 9 - - return []string{"-Werror", "-Wall", "-std=c11", "-nostdlibinc"} 10 - + return []string{"-Werror", "-Wall", "-std=c11", "-isystem", "@clang_include@"} 11 - }, 12 - sourceDir: func() string { 13 - llvmDir := filepath.Join(goenv.Get("TINYGOROOT"), "llvm-project/compiler-rt/lib/builtins") 14 - diff --git a/builder/picolibc.go b/builder/picolibc.go 15 - index 1b7c748b..8a6b9ddd 100644 16 - --- a/builder/picolibc.go 17 - +++ b/builder/picolibc.go 18 - @@ -32,7 +32,7 @@ var Picolibc = Library{ 19 - "-D__OBSOLETE_MATH_FLOAT=1", // use old math code that doesn't expect a FPU 20 - "-D__OBSOLETE_MATH_DOUBLE=0", 21 - "-D_WANT_IO_C99_FORMATS", 22 - - "-nostdlibinc", 23 - + "-isystem", "@clang_include@", 24 - "-isystem", newlibDir + "/libc/include", 25 - "-I" + newlibDir + "/libc/tinystdio", 26 - "-I" + newlibDir + "/libm/common", 1 + diff --git a/builder/library.go b/builder/library.go 2 + index 6517355b..b8de1894 100644 3 + --- a/builder/library.go 4 + +++ b/builder/library.go 5 + @@ -142,7 +142,7 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ 6 + // Note: -fdebug-prefix-map is necessary to make the output archive 7 + // reproducible. Otherwise the temporary directory is stored in the archive 8 + // itself, which varies each run. 9 + - args := append(l.cflags(target, headerPath), "-c", "-Oz", "-gdwarf-4", "-ffunction-sections", "-fdata-sections", "-Wno-macro-redefined", "--target="+target, "-fdebug-prefix-map="+dir+"="+remapDir) 10 + + 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@") 11 + cpu := config.CPU() 12 + if cpu != "" { 13 + // X86 has deprecated the -mcpu flag, so we need to use -march instead. 27 14 diff --git a/compileopts/config.go b/compileopts/config.go 28 - index 9a4bc310..424421ae 100644 15 + index 39fc4f2a..8711b5a8 100644 29 16 --- a/compileopts/config.go 30 17 +++ b/compileopts/config.go 31 - @@ -276,6 +276,7 @@ func (c *Config) CFlags() []string { 32 - path, _ := c.LibcPath("picolibc") 33 - cflags = append(cflags, 34 - "--sysroot="+path, 35 - + "-isystem", "@clang_include@", 36 - "-isystem", filepath.Join(path, "include"), // necessary for Xtensa 37 - "-isystem", filepath.Join(picolibcDir, "include"), 38 - "-isystem", filepath.Join(picolibcDir, "tinystdio"), 39 - @@ -285,7 +286,6 @@ func (c *Config) CFlags() []string { 40 - path, _ := c.LibcPath("musl") 41 - arch := MuslArchitecture(c.Triple()) 42 - cflags = append(cflags, 43 - - "-nostdlibinc", 44 - "-isystem", filepath.Join(path, "include"), 45 - "-isystem", filepath.Join(root, "lib", "musl", "arch", arch), 46 - "-isystem", filepath.Join(root, "lib", "musl", "include"), 18 + @@ -264,6 +264,7 @@ func (c *Config) CFlags() []string { 19 + for _, flag := range c.Target.CFlags { 20 + cflags = append(cflags, strings.ReplaceAll(flag, "{root}", goenv.Get("TINYGOROOT"))) 21 + } 22 + + cflags = append([]string{"-isystem", "@clang_include@"}, cflags...) 23 + switch c.Target.Libc { 24 + case "darwin-libSystem": 25 + root := goenv.Get("TINYGOROOT")
+11 -3
pkgs/development/compilers/tinygo/default.nix
··· 54 54 patches = [ 55 55 ./0001-Makefile.patch 56 56 57 + # clang.cc does not have any paths in the include path. 58 + # For TinyGo, we want to have no include paths, _except_ for the built-in 59 + # Clang header files (things like stdint.h). That's why we use -nostdlibinc. 60 + # So to make Clang work like we want, we will have to manually add this one 61 + # include path. 62 + # We can't use a regular clang command (something like 63 + # llvmPackages.clangUseLLVM) because there are various bugs, see: 64 + # https://github.com/NixOS/nixpkgs/issues/259397 65 + # https://github.com/NixOS/nixpkgs/issues/259386 57 66 (substituteAll { 58 67 src = ./0002-Add-clang-header-path.patch; 59 68 clang_include = "${clang.cc.lib}/lib/clang/${llvmMajor}/include"; ··· 108 117 substituteInPlace builder/buildid.go \ 109 118 --replace "OUT_PATH" "$out" 110 119 111 - # TODO: Fix mingw and darwin 112 - # Disable windows and darwin cross-compile tests 120 + # TODO: Fix mingw 121 + # Disable windows cross-compile tests 113 122 sed -i "/GOOS=windows/d" Makefile 114 - sed -i "/GOOS=darwin/d" Makefile 115 123 '' + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' 116 124 substituteInPlace Makefile \ 117 125 --replace "./build/tinygo" "${buildPackages.tinygo}/bin/tinygo"