lol

tinygo: 0.30.0 -> 0.31.1

I've dropped a number of patches that were unnecessary after some
improvements in TinyGo to make it work better with in a Nix environment.

+15 -154
+3 -10
pkgs/development/compilers/tinygo/0001-Makefile.patch pkgs/development/compilers/tinygo/0001-GNUmakefile.patch
··· 1 - From ef066db7f5cb7f551f88fb218c82fc947e464425 Mon Sep 17 00:00:00 2001 2 - From: =?UTF-8?q?Mustafa=20=C3=87al=C4=B1=C5=9Fkan?= <muscaln@protonmail.com> 3 - Date: Sun, 3 Jul 2022 14:30:51 +0300 4 - Subject: [PATCH 1/3] Makefile 5 - 6 - 7 - diff --git a/Makefile b/Makefile 8 - index 60a5a574..904d2db5 100644 9 - --- a/Makefile 10 - +++ b/Makefile 1 + diff --git a/GNUmakefile b/GNUmakefile 2 + --- a/GNUmakefile 3 + +++ b/GNUmakefile 11 4 @@ -14,11 +14,6 @@ LLVM_VERSIONS = 14 13 12 11 12 5 errifempty = $(if $(1),$(1),$(error $(2))) 13 6 detect = $(shell which $(call errifempty,$(firstword $(foreach p,$(2),$(shell command -v $(p) 2> /dev/null && echo $(p)))),failed to locate $(1) at any of: $(2)))
-25
pkgs/development/compilers/tinygo/0002-Add-clang-header-path.patch
··· 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. 14 - diff --git a/compileopts/config.go b/compileopts/config.go 15 - index 39fc4f2a..8711b5a8 100644 16 - --- a/compileopts/config.go 17 - +++ b/compileopts/config.go 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")
-56
pkgs/development/compilers/tinygo/0003-Use-out-path-as-build-id-on-darwin.patch
··· 1 - From e7357c383188dd735592bd9f2202d2afcfffa39d Mon Sep 17 00:00:00 2001 2 - From: =?UTF-8?q?Mustafa=20=C3=87al=C4=B1=C5=9Fkan?= <muscaln@protonmail.com> 3 - Date: Sun, 11 Sep 2022 17:08:33 +0300 4 - Subject: [PATCH 3/3] Use out path as build id on darwin 5 - 6 - 7 - diff --git a/builder/buildid.go b/builder/buildid.go 8 - index e6527700..65cb08e8 100644 9 - --- a/builder/buildid.go 10 - +++ b/builder/buildid.go 11 - @@ -3,8 +3,6 @@ package builder 12 - import ( 13 - "bytes" 14 - "debug/elf" 15 - - "debug/macho" 16 - - "encoding/binary" 17 - "fmt" 18 - "io" 19 - "os" 20 - @@ -53,30 +51,9 @@ func ReadBuildID() ([]byte, error) { 21 - return goID, nil 22 - } 23 - case "darwin": 24 - - // Read the LC_UUID load command, which contains the equivalent of a 25 - - // build ID. 26 - - file, err := macho.NewFile(f) 27 - - if err != nil { 28 - - return nil, err 29 - - } 30 - - for _, load := range file.Loads { 31 - - // Unfortunately, the debug/macho package doesn't support the 32 - - // LC_UUID command directly. So we have to read it from 33 - - // macho.LoadBytes. 34 - - load, ok := load.(macho.LoadBytes) 35 - - if !ok { 36 - - continue 37 - - } 38 - - raw := load.Raw() 39 - - command := binary.LittleEndian.Uint32(raw) 40 - - if command != 0x1b { 41 - - // Looking for the LC_UUID load command. 42 - - // LC_UUID is defined here as 0x1b: 43 - - // https://opensource.apple.com/source/xnu/xnu-4570.71.2/EXTERNAL_HEADERS/mach-o/loader.h.auto.html 44 - - continue 45 - - } 46 - - return raw[4:], nil 47 - - } 48 - + // On darwin, os.Executable() returns broken path in nix build environment 49 - + // So we are using $out path as build id since its also unique 50 - + return []byte("OUT_PATH"), nil 51 - default: 52 - // On other platforms (such as Windows) there isn't such a convenient 53 - // build ID. Luckily, Go does have an equivalent of the build ID, which 54 - -- 55 - 2.37.2 56 -
-12
pkgs/development/compilers/tinygo/0004-fix-darwin-build.patch
··· 1 - diff --git a/compileopts/config.go b/compileopts/config.go 2 - index 39fc4f2a..fb5d4575 100644 3 - --- a/compileopts/config.go 4 - +++ b/compileopts/config.go 5 - @@ -269,6 +269,7 @@ func (c *Config) CFlags() []string { 6 - root := goenv.Get("TINYGOROOT") 7 - cflags = append(cflags, 8 - "--sysroot="+filepath.Join(root, "lib/macos-minimal-sdk/src"), 9 - + "-isystem", filepath.Join(root, "lib/macos-minimal-sdk/src/usr/include"), // necessary for Nix 10 - ) 11 - case "picolibc": 12 - root := goenv.Get("TINYGOROOT")
+11 -50
pkgs/development/compilers/tinygo/default.nix
··· 4 4 , buildGoModule 5 5 , fetchFromGitHub 6 6 , makeWrapper 7 - , substituteAll 8 7 , llvmPackages 9 8 , go 10 - , libffi 11 - , zlib 12 - , ncurses 13 - , libxml2 14 9 , xar 15 10 , wasi-libc 16 11 , binaryen ··· 39 34 40 35 buildGoModule rec { 41 36 pname = "tinygo"; 42 - version = "0.30.0"; 37 + version = "0.31.1"; 43 38 44 39 src = fetchFromGitHub { 45 40 owner = "tinygo-org"; 46 41 repo = "tinygo"; 47 42 rev = "v${version}"; 48 - sha256 = "sha256-hOccfMKuvTKYKDRcEgTJ8k/c/H+qNDpvotWIqk6p2u8="; 43 + sha256 = "sha256-YocRTgGSyjnQsYd4a2nCQ0vdQi/z2gHPguix5xIkkgc="; 49 44 fetchSubmodules = true; 50 45 }; 51 46 52 - vendorHash = "sha256-2q3N6QhfRmwbs4CTWrFWr1wyhf2jPS2ECAn/wrrpXdM="; 47 + vendorHash = "sha256-HZiyAgsTEBQv+Qp0T9RXTV1lkxvIGh7Q45rd45cfvjo="; 53 48 54 49 patches = [ 55 - ./0001-Makefile.patch 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 66 - (substituteAll { 67 - src = ./0002-Add-clang-header-path.patch; 68 - clang_include = "${clang.cc.lib}/lib/clang/${llvmMajor}/include"; 69 - }) 70 - 71 - #TODO(muscaln): Find a better way to fix build ID on darwin 72 - ./0003-Use-out-path-as-build-id-on-darwin.patch 73 - ./0004-fix-darwin-build.patch 50 + ./0001-GNUmakefile.patch 74 51 ]; 75 52 76 53 nativeCheckInputs = [ binaryen ]; 77 54 nativeBuildInputs = [ makeWrapper ]; 78 55 buildInputs = [ llvm clang.cc ] 79 - ++ lib.optionals stdenv.isDarwin [ zlib ncurses libffi libxml2 xar ]; 56 + ++ lib.optionals stdenv.isDarwin [ xar ]; 80 57 81 58 doCheck = (stdenv.buildPlatform.canExecute stdenv.hostPlatform); 82 59 inherit tinygoTests; 83 60 84 61 allowGoReference = true; 85 - tags = [ "llvm${llvmMajor}" ]; 86 - ldflags = [ "-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=${placeholder "out"}/share/tinygo" ]; 62 + ldflags = [ 63 + "-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=${placeholder "out"}/share/tinygo" 64 + "-X github.com/tinygo-org/tinygo/goenv.clangResourceDir=${clang.cc.lib}/lib/clang/${llvmMajor}" 65 + ]; 87 66 subPackages = [ "." ]; 88 67 89 68 # Output contains static libraries for different arm cpus 90 69 # and stripping could mess up these so only strip the compiler 91 70 stripDebugList = [ "bin" ]; 92 71 93 - postConfigure = lib.optionalString stdenv.isDarwin '' 94 - for i in vendor/tinygo.org/x/go-llvm/llvm_config_darwin*; do 95 - substituteInPlace $i --replace "curses" "ncurses" 96 - done 97 - ''; 98 - 99 72 postPatch = '' 100 73 # Copy wasi-libc, symlink seems not working 101 74 rm -rf lib/wasi-libc/* ··· 108 81 mkdir -p lib/compiler-rt-builtins 109 82 cp -a ${compiler-rt.src}/compiler-rt/lib/builtins/* lib/compiler-rt-builtins/ 110 83 111 - substituteInPlace Makefile \ 112 - --replace "\$(TINYGO)" "$(pwd)/build/tinygo" \ 113 - --replace "@\$(MD5SUM)" "md5sum" \ 84 + substituteInPlace GNUmakefile \ 114 85 --replace "build/release/tinygo/bin" "$out/bin" \ 115 86 --replace "build/release/" "$out/share/" 116 - 117 - substituteInPlace builder/buildid.go \ 118 - --replace "OUT_PATH" "$out" 119 - 120 - # TODO: Fix mingw 121 - # Disable windows cross-compile tests 122 - sed -i "/GOOS=windows/d" Makefile 123 - '' + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' 124 - substituteInPlace Makefile \ 125 - --replace "./build/tinygo" "${buildPackages.tinygo}/bin/tinygo" 126 87 ''; 127 88 128 89 preBuild = '' ··· 141 102 ''; 142 103 143 104 checkPhase = lib.optionalString (tinygoTests != [ ] && tinygoTests != null) '' 144 - make ''${tinygoTests[@]} XTENSA=0 105 + make ''${tinygoTests[@]} TINYGO="$(pwd)/build/tinygo" MD5SUM=md5sum XTENSA=0 145 106 ''; 146 107 147 108 installPhase = ''
+1 -1
pkgs/top-level/all-packages.nix
··· 17208 17208 tinycc = darwin.apple_sdk_11_0.callPackage ../development/compilers/tinycc { }; 17209 17209 17210 17210 tinygo = callPackage ../development/compilers/tinygo { 17211 - llvmPackages = llvmPackages_16; 17211 + llvmPackages = llvmPackages_17; 17212 17212 wasi-libc = pkgsCross.wasi32.wasilibc; 17213 17213 }; 17214 17214