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

tinygo: clean up Clang header path patch
This commit is contained in:
maxine 2023-10-13 15:39:45 +02:00 committed by GitHub
commit 00ee862b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 46 deletions

View File

@ -1,46 +1,25 @@
diff --git a/builder/builtins.go b/builder/builtins.go
index a1066b67..f4f8ca79 100644
--- a/builder/builtins.go
+++ b/builder/builtins.go
@@ -179,7 +179,7 @@ var avrBuiltins = []string{
var CompilerRT = Library{
name: "compiler-rt",
cflags: func(target, headerPath string) []string {
- return []string{"-Werror", "-Wall", "-std=c11", "-nostdlibinc"}
+ return []string{"-Werror", "-Wall", "-std=c11", "-isystem", "@clang_include@"}
},
sourceDir: func() string {
llvmDir := filepath.Join(goenv.Get("TINYGOROOT"), "llvm-project/compiler-rt/lib/builtins")
diff --git a/builder/picolibc.go b/builder/picolibc.go
index 1b7c748b..8a6b9ddd 100644
--- a/builder/picolibc.go
+++ b/builder/picolibc.go
@@ -32,7 +32,7 @@ var Picolibc = Library{
"-D__OBSOLETE_MATH_FLOAT=1", // use old math code that doesn't expect a FPU
"-D__OBSOLETE_MATH_DOUBLE=0",
"-D_WANT_IO_C99_FORMATS",
- "-nostdlibinc",
+ "-isystem", "@clang_include@",
"-isystem", newlibDir + "/libc/include",
"-I" + newlibDir + "/libc/tinystdio",
"-I" + newlibDir + "/libm/common",
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 9a4bc310..424421ae 100644
index 39fc4f2a..8711b5a8 100644
--- a/compileopts/config.go
+++ b/compileopts/config.go
@@ -276,6 +276,7 @@ func (c *Config) CFlags() []string {
path, _ := c.LibcPath("picolibc")
cflags = append(cflags,
"--sysroot="+path,
+ "-isystem", "@clang_include@",
"-isystem", filepath.Join(path, "include"), // necessary for Xtensa
"-isystem", filepath.Join(picolibcDir, "include"),
"-isystem", filepath.Join(picolibcDir, "tinystdio"),
@@ -285,7 +286,6 @@ func (c *Config) CFlags() []string {
path, _ := c.LibcPath("musl")
arch := MuslArchitecture(c.Triple())
cflags = append(cflags,
- "-nostdlibinc",
"-isystem", filepath.Join(path, "include"),
"-isystem", filepath.Join(root, "lib", "musl", "arch", arch),
"-isystem", filepath.Join(root, "lib", "musl", "include"),
@@ -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")

View File

@ -54,6 +54,15 @@ buildGoModule rec {
patches = [
./0001-Makefile.patch
# clang.cc does not have any paths in the include path.
# For TinyGo, we want to have no include paths, _except_ for the built-in
# Clang header files (things like stdint.h). That's why we use -nostdlibinc.
# So to make Clang work like we want, we will have to manually add this one
# include path.
# We can't use a regular clang command (something like
# llvmPackages.clangUseLLVM) because there are various bugs, see:
# https://github.com/NixOS/nixpkgs/issues/259397
# https://github.com/NixOS/nixpkgs/issues/259386
(substituteAll {
src = ./0002-Add-clang-header-path.patch;
clang_include = "${clang.cc.lib}/lib/clang/${llvmMajor}/include";
@ -108,10 +117,9 @@ buildGoModule rec {
substituteInPlace builder/buildid.go \
--replace "OUT_PATH" "$out"
# TODO: Fix mingw and darwin
# Disable windows and darwin cross-compile tests
# TODO: Fix mingw
# Disable windows cross-compile tests
sed -i "/GOOS=windows/d" Makefile
sed -i "/GOOS=darwin/d" Makefile
'' + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
substituteInPlace Makefile \
--replace "./build/tinygo" "${buildPackages.tinygo}/bin/tinygo"