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.
This commit is contained in:
parent
49a6ffcb8f
commit
044b2be6a1
@ -1,13 +1,6 @@
|
||||
From ef066db7f5cb7f551f88fb218c82fc947e464425 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Mustafa=20=C3=87al=C4=B1=C5=9Fkan?= <muscaln@protonmail.com>
|
||||
Date: Sun, 3 Jul 2022 14:30:51 +0300
|
||||
Subject: [PATCH 1/3] Makefile
|
||||
|
||||
|
||||
diff --git a/Makefile b/Makefile
|
||||
index 60a5a574..904d2db5 100644
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
diff --git a/GNUmakefile b/GNUmakefile
|
||||
--- a/GNUmakefile
|
||||
+++ b/GNUmakefile
|
||||
@@ -14,11 +14,6 @@ LLVM_VERSIONS = 14 13 12 11
|
||||
errifempty = $(if $(1),$(1),$(error $(2)))
|
||||
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)))
|
@ -1,25 +0,0 @@
|
||||
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")
|
@ -1,56 +0,0 @@
|
||||
From e7357c383188dd735592bd9f2202d2afcfffa39d Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Mustafa=20=C3=87al=C4=B1=C5=9Fkan?= <muscaln@protonmail.com>
|
||||
Date: Sun, 11 Sep 2022 17:08:33 +0300
|
||||
Subject: [PATCH 3/3] Use out path as build id on darwin
|
||||
|
||||
|
||||
diff --git a/builder/buildid.go b/builder/buildid.go
|
||||
index e6527700..65cb08e8 100644
|
||||
--- a/builder/buildid.go
|
||||
+++ b/builder/buildid.go
|
||||
@@ -3,8 +3,6 @@ package builder
|
||||
import (
|
||||
"bytes"
|
||||
"debug/elf"
|
||||
- "debug/macho"
|
||||
- "encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -53,30 +51,9 @@ func ReadBuildID() ([]byte, error) {
|
||||
return goID, nil
|
||||
}
|
||||
case "darwin":
|
||||
- // Read the LC_UUID load command, which contains the equivalent of a
|
||||
- // build ID.
|
||||
- file, err := macho.NewFile(f)
|
||||
- if err != nil {
|
||||
- return nil, err
|
||||
- }
|
||||
- for _, load := range file.Loads {
|
||||
- // Unfortunately, the debug/macho package doesn't support the
|
||||
- // LC_UUID command directly. So we have to read it from
|
||||
- // macho.LoadBytes.
|
||||
- load, ok := load.(macho.LoadBytes)
|
||||
- if !ok {
|
||||
- continue
|
||||
- }
|
||||
- raw := load.Raw()
|
||||
- command := binary.LittleEndian.Uint32(raw)
|
||||
- if command != 0x1b {
|
||||
- // Looking for the LC_UUID load command.
|
||||
- // LC_UUID is defined here as 0x1b:
|
||||
- // https://opensource.apple.com/source/xnu/xnu-4570.71.2/EXTERNAL_HEADERS/mach-o/loader.h.auto.html
|
||||
- continue
|
||||
- }
|
||||
- return raw[4:], nil
|
||||
- }
|
||||
+ // On darwin, os.Executable() returns broken path in nix build environment
|
||||
+ // So we are using $out path as build id since its also unique
|
||||
+ return []byte("OUT_PATH"), nil
|
||||
default:
|
||||
// On other platforms (such as Windows) there isn't such a convenient
|
||||
// build ID. Luckily, Go does have an equivalent of the build ID, which
|
||||
--
|
||||
2.37.2
|
||||
|
@ -1,12 +0,0 @@
|
||||
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")
|
@ -4,13 +4,8 @@
|
||||
, buildGoModule
|
||||
, fetchFromGitHub
|
||||
, makeWrapper
|
||||
, substituteAll
|
||||
, llvmPackages
|
||||
, go
|
||||
, libffi
|
||||
, zlib
|
||||
, ncurses
|
||||
, libxml2
|
||||
, xar
|
||||
, wasi-libc
|
||||
, binaryen
|
||||
@ -39,63 +34,41 @@ in
|
||||
|
||||
buildGoModule rec {
|
||||
pname = "tinygo";
|
||||
version = "0.30.0";
|
||||
version = "0.31.1";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "tinygo-org";
|
||||
repo = "tinygo";
|
||||
rev = "v${version}";
|
||||
sha256 = "sha256-hOccfMKuvTKYKDRcEgTJ8k/c/H+qNDpvotWIqk6p2u8=";
|
||||
sha256 = "sha256-YocRTgGSyjnQsYd4a2nCQ0vdQi/z2gHPguix5xIkkgc=";
|
||||
fetchSubmodules = true;
|
||||
};
|
||||
|
||||
vendorHash = "sha256-2q3N6QhfRmwbs4CTWrFWr1wyhf2jPS2ECAn/wrrpXdM=";
|
||||
vendorHash = "sha256-HZiyAgsTEBQv+Qp0T9RXTV1lkxvIGh7Q45rd45cfvjo=";
|
||||
|
||||
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";
|
||||
})
|
||||
|
||||
#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
|
||||
./0001-GNUmakefile.patch
|
||||
];
|
||||
|
||||
nativeCheckInputs = [ binaryen ];
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
buildInputs = [ llvm clang.cc ]
|
||||
++ lib.optionals stdenv.isDarwin [ zlib ncurses libffi libxml2 xar ];
|
||||
++ lib.optionals stdenv.isDarwin [ xar ];
|
||||
|
||||
doCheck = (stdenv.buildPlatform.canExecute stdenv.hostPlatform);
|
||||
inherit tinygoTests;
|
||||
|
||||
allowGoReference = true;
|
||||
tags = [ "llvm${llvmMajor}" ];
|
||||
ldflags = [ "-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=${placeholder "out"}/share/tinygo" ];
|
||||
ldflags = [
|
||||
"-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=${placeholder "out"}/share/tinygo"
|
||||
"-X github.com/tinygo-org/tinygo/goenv.clangResourceDir=${clang.cc.lib}/lib/clang/${llvmMajor}"
|
||||
];
|
||||
subPackages = [ "." ];
|
||||
|
||||
# Output contains static libraries for different arm cpus
|
||||
# and stripping could mess up these so only strip the compiler
|
||||
stripDebugList = [ "bin" ];
|
||||
|
||||
postConfigure = lib.optionalString stdenv.isDarwin ''
|
||||
for i in vendor/tinygo.org/x/go-llvm/llvm_config_darwin*; do
|
||||
substituteInPlace $i --replace "curses" "ncurses"
|
||||
done
|
||||
'';
|
||||
|
||||
postPatch = ''
|
||||
# Copy wasi-libc, symlink seems not working
|
||||
rm -rf lib/wasi-libc/*
|
||||
@ -108,21 +81,9 @@ buildGoModule rec {
|
||||
mkdir -p lib/compiler-rt-builtins
|
||||
cp -a ${compiler-rt.src}/compiler-rt/lib/builtins/* lib/compiler-rt-builtins/
|
||||
|
||||
substituteInPlace Makefile \
|
||||
--replace "\$(TINYGO)" "$(pwd)/build/tinygo" \
|
||||
--replace "@\$(MD5SUM)" "md5sum" \
|
||||
substituteInPlace GNUmakefile \
|
||||
--replace "build/release/tinygo/bin" "$out/bin" \
|
||||
--replace "build/release/" "$out/share/"
|
||||
|
||||
substituteInPlace builder/buildid.go \
|
||||
--replace "OUT_PATH" "$out"
|
||||
|
||||
# TODO: Fix mingw
|
||||
# Disable windows cross-compile tests
|
||||
sed -i "/GOOS=windows/d" Makefile
|
||||
'' + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
|
||||
substituteInPlace Makefile \
|
||||
--replace "./build/tinygo" "${buildPackages.tinygo}/bin/tinygo"
|
||||
'';
|
||||
|
||||
preBuild = ''
|
||||
@ -141,7 +102,7 @@ buildGoModule rec {
|
||||
'';
|
||||
|
||||
checkPhase = lib.optionalString (tinygoTests != [ ] && tinygoTests != null) ''
|
||||
make ''${tinygoTests[@]} XTENSA=0
|
||||
make ''${tinygoTests[@]} TINYGO="$(pwd)/build/tinygo" MD5SUM=md5sum XTENSA=0
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
|
@ -17208,7 +17208,7 @@ with pkgs;
|
||||
tinycc = darwin.apple_sdk_11_0.callPackage ../development/compilers/tinycc { };
|
||||
|
||||
tinygo = callPackage ../development/compilers/tinygo {
|
||||
llvmPackages = llvmPackages_16;
|
||||
llvmPackages = llvmPackages_17;
|
||||
wasi-libc = pkgsCross.wasi32.wasilibc;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user