From 16ef368cfbf7d28d61e04eee20dace02d02c385b Mon Sep 17 00:00:00 2001 From: Kirill Radzikhovskyy Date: Sun, 23 Jul 2023 07:09:32 +1000 Subject: [PATCH] tinygo: 0.26.0 -> 0.30.0 --- .../tinygo/0002-Add-clang-header-path.patch | 25 +++++-------- .../tinygo/0004-fix-darwin-build.patch | 12 +++++++ pkgs/development/compilers/tinygo/default.nix | 35 +++++++------------ pkgs/top-level/all-packages.nix | 6 +--- 4 files changed, 33 insertions(+), 45 deletions(-) create mode 100644 pkgs/development/compilers/tinygo/0004-fix-darwin-build.patch diff --git a/pkgs/development/compilers/tinygo/0002-Add-clang-header-path.patch b/pkgs/development/compilers/tinygo/0002-Add-clang-header-path.patch index 7e4c8eded677..1cf15a219fa2 100644 --- a/pkgs/development/compilers/tinygo/0002-Add-clang-header-path.patch +++ b/pkgs/development/compilers/tinygo/0002-Add-clang-header-path.patch @@ -1,14 +1,8 @@ -From 301b2d82cdbfaffe4dfba1d2cfed068a4115f730 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Mustafa=20=C3=87al=C4=B1=C5=9Fkan?= -Date: Sat, 30 Apr 2022 16:18:31 +0300 -Subject: [PATCH 2/3] Add clang header path - - diff --git a/builder/builtins.go b/builder/builtins.go -index 121398fa..a589988b 100644 +index a1066b67..f4f8ca79 100644 --- a/builder/builtins.go +++ b/builder/builtins.go -@@ -170,7 +170,7 @@ var aeabiBuiltins = []string{ +@@ -179,7 +179,7 @@ var avrBuiltins = []string{ var CompilerRT = Library{ name: "compiler-rt", cflags: func(target, headerPath string) []string { @@ -18,23 +12,23 @@ index 121398fa..a589988b 100644 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 d0786ee3..9a5cf9b0 100644 +index 1b7c748b..8a6b9ddd 100644 --- a/builder/picolibc.go +++ b/builder/picolibc.go -@@ -30,7 +30,7 @@ var Picolibc = Library{ - "-D_IEEE_LIBM", +@@ -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/compileopts/config.go b/compileopts/config.go -index a006b673..3a105b49 100644 +index 9a4bc310..424421ae 100644 --- a/compileopts/config.go +++ b/compileopts/config.go -@@ -279,6 +279,7 @@ func (c *Config) CFlags() []string { +@@ -276,6 +276,7 @@ func (c *Config) CFlags() []string { path, _ := c.LibcPath("picolibc") cflags = append(cflags, "--sysroot="+path, @@ -42,7 +36,7 @@ index a006b673..3a105b49 100644 "-isystem", filepath.Join(path, "include"), // necessary for Xtensa "-isystem", filepath.Join(picolibcDir, "include"), "-isystem", filepath.Join(picolibcDir, "tinystdio"), -@@ -288,7 +289,6 @@ func (c *Config) CFlags() []string { +@@ -285,7 +286,6 @@ func (c *Config) CFlags() []string { path, _ := c.LibcPath("musl") arch := MuslArchitecture(c.Triple()) cflags = append(cflags, @@ -50,6 +44,3 @@ index a006b673..3a105b49 100644 "-isystem", filepath.Join(path, "include"), "-isystem", filepath.Join(root, "lib", "musl", "arch", arch), "-isystem", filepath.Join(root, "lib", "musl", "include"), --- -2.37.2 - diff --git a/pkgs/development/compilers/tinygo/0004-fix-darwin-build.patch b/pkgs/development/compilers/tinygo/0004-fix-darwin-build.patch new file mode 100644 index 000000000000..924533a49131 --- /dev/null +++ b/pkgs/development/compilers/tinygo/0004-fix-darwin-build.patch @@ -0,0 +1,12 @@ +diff --git a/compileopts/config.go b/compileopts/config.go +index 39fc4f2a..fb5d4575 100644 +--- a/compileopts/config.go ++++ b/compileopts/config.go +@@ -269,6 +269,7 @@ func (c *Config) CFlags() []string { + root := goenv.Get("TINYGOROOT") + cflags = append(cflags, + "--sysroot="+filepath.Join(root, "lib/macos-minimal-sdk/src"), ++ "-isystem", filepath.Join(root, "lib/macos-minimal-sdk/src/usr/include"), // necessary for Nix + ) + case "picolibc": + root := goenv.Get("TINYGOROOT") diff --git a/pkgs/development/compilers/tinygo/default.nix b/pkgs/development/compilers/tinygo/default.nix index 6e59699ea9dc..d032f139e334 100644 --- a/pkgs/development/compilers/tinygo/default.nix +++ b/pkgs/development/compilers/tinygo/default.nix @@ -13,7 +13,6 @@ , libxml2 , xar , wasi-libc -, avrgcc , binaryen , avrdude , gdb @@ -33,37 +32,39 @@ let ln -s ${lib.getBin clang.cc}/bin/clang $out/clang-${llvmMajor} ln -s ${lib.getBin lld}/bin/ld.lld $out/ld.lld-${llvmMajor} ln -s ${lib.getBin lld}/bin/wasm-ld $out/wasm-ld-${llvmMajor} - ln -s ${gdb}/bin/gdb $out/gdb-multiarch + # GDB upstream does not support ARM darwin + ${lib.optionalString (!(stdenv.isDarwin && stdenv.isAarch64)) "ln -s ${gdb}/bin/gdb $out/gdb-multiarch" } ''; in buildGoModule rec { pname = "tinygo"; - version = "0.26.0"; + version = "0.30.0"; src = fetchFromGitHub { owner = "tinygo-org"; repo = "tinygo"; rev = "v${version}"; - sha256 = "rI8CADPWKdNvfknEsrpp2pCeZobf9fAp0GDIWjupzZA="; + sha256 = "sha256-hOccfMKuvTKYKDRcEgTJ8k/c/H+qNDpvotWIqk6p2u8="; fetchSubmodules = true; }; - vendorHash = "sha256-ihQd/RAjAQhgQZHbNiWmAD0eOo1MvqAR/OwIOUWtdAM="; + vendorHash = "sha256-2q3N6QhfRmwbs4CTWrFWr1wyhf2jPS2ECAn/wrrpXdM="; patches = [ ./0001-Makefile.patch (substituteAll { src = ./0002-Add-clang-header-path.patch; - clang_include = "${clang.cc.lib}/lib/clang/${clang.cc.version}/include"; + clang_include = "${clang.cc.lib}/lib/clang/${llvmMajor}/include"; }) #TODO(muscaln): Find a better way to fix build ID on darwin ./0003-Use-out-path-as-build-id-on-darwin.patch + ./0004-fix-darwin-build.patch ]; - nativeCheckInputs = [ avrgcc binaryen ]; + nativeCheckInputs = [ binaryen ]; nativeBuildInputs = [ makeWrapper ]; buildInputs = [ llvm clang.cc ] ++ lib.optionals stdenv.isDarwin [ zlib ncurses libffi libxml2 xar ]; @@ -121,30 +122,18 @@ buildGoModule rec { export HOME=$TMPDIR ''; - postBuild = let - tinygoForBuild = if (stdenv.buildPlatform.canExecute stdenv.hostPlatform) - then "build/tinygo" - else "${buildPackages.tinygo}/bin/tinygo"; - in '' + postBuild = '' # Move binary mkdir -p build mv $GOPATH/bin/tinygo build/tinygo - make gen-device + make gen-device -j $NIX_BUILD_CORES export TINYGOROOT=$(pwd) - finalRoot=$out/share/tinygo - - for target in thumbv6m-unknown-unknown-eabi-cortex-m0 thumbv6m-unknown-unknown-eabi-cortex-m0plus thumbv7em-unknown-unknown-eabi-cortex-m4; do - mkdir -p $finalRoot/pkg/$target - for lib in compiler-rt picolibc; do - ${tinygoForBuild} build-library -target=''${target#*eabi-} -o $finalRoot/pkg/$target/$lib $lib - done - done ''; checkPhase = lib.optionalString (tinygoTests != [ ] && tinygoTests != null) '' - make ''${tinygoTests[@]} XTENSA=0 ${lib.optionalString stdenv.isDarwin "AVR=0"} + make ''${tinygoTests[@]} XTENSA=0 ''; installPhase = '' @@ -153,7 +142,7 @@ buildGoModule rec { make build/release wrapProgram $out/bin/tinygo \ - --prefix PATH : ${lib.makeBinPath [ go avrdude openocd avrgcc binaryen ]}:${bootstrapTools} + --prefix PATH : ${lib.makeBinPath [ go avrdude openocd binaryen ]}:${bootstrapTools} runHook postInstall ''; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 7a590c236b41..6c3f581ce5af 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17569,12 +17569,8 @@ with pkgs; tinycc = darwin.apple_sdk_11_0.callPackage ../development/compilers/tinycc { }; tinygo = callPackage ../development/compilers/tinygo { - llvmPackages = llvmPackages_14; - avrgcc = pkgsCross.avr.buildPackages.gcc; + llvmPackages = llvmPackages_16; wasi-libc = pkgsCross.wasi32.wasilibc; - # go 1.20 build failure - go = go_1_19; - buildGoModule = buildGo119Module; }; tinyscheme = callPackage ../development/interpreters/tinyscheme { };