commit
437fd89069
@ -0,0 +1,57 @@ |
|||||||
|
From fcae473c4b6ac2120ec75c321d6db850d8ecd6a9 Mon Sep 17 00:00:00 2001
|
||||||
|
From: =?UTF-8?q?Mustafa=20=C3=87al=C4=B1=C5=9Fkan?= <muscaln@protonmail.com>
|
||||||
|
Date: Sat, 30 Apr 2022 16:37:44 +0300
|
||||||
|
Subject: [PATCH 1/3] Makefile
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/Makefile b/Makefile
|
||||||
|
index dc388c21..7efc9901 100644
|
||||||
|
--- a/Makefile
|
||||||
|
+++ b/Makefile
|
||||||
|
@@ -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)))
|
||||||
|
toolSearchPathsVersion = $(1)-$(2)
|
||||||
|
-ifeq ($(shell uname -s),Darwin)
|
||||||
|
- # Also explicitly search Brew's copy, which is not in PATH by default.
|
||||||
|
- BREW_PREFIX := $(shell brew --prefix)
|
||||||
|
- toolSearchPathsVersion += $(BREW_PREFIX)/opt/llvm@$(2)/bin/$(1)-$(2) $(BREW_PREFIX)/opt/llvm@$(2)/bin/$(1)
|
||||||
|
-endif
|
||||||
|
# First search for a custom built copy, then move on to explicitly version-tagged binaries, then just see if the tool is in path with its normal name.
|
||||||
|
findLLVMTool = $(call detect,$(1),$(abspath llvm-build/bin/$(1)) $(foreach ver,$(LLVM_VERSIONS),$(call toolSearchPathsVersion,$(1),$(ver))) $(1))
|
||||||
|
CLANG ?= $(call findLLVMTool,clang)
|
||||||
|
@@ -644,9 +639,8 @@ endif
|
||||||
|
wasmtest:
|
||||||
|
$(GO) test ./tests/wasm
|
||||||
|
|
||||||
|
-build/release: tinygo gen-device wasi-libc $(if $(filter 1,$(USE_SYSTEM_BINARYEN)),,binaryen)
|
||||||
|
+build/release:
|
||||||
|
@mkdir -p build/release/tinygo/bin
|
||||||
|
- @mkdir -p build/release/tinygo/lib/clang/include
|
||||||
|
@mkdir -p build/release/tinygo/lib/CMSIS/CMSIS
|
||||||
|
@mkdir -p build/release/tinygo/lib/macos-minimal-sdk
|
||||||
|
@mkdir -p build/release/tinygo/lib/mingw-w64/mingw-w64-crt/lib-common
|
||||||
|
@@ -663,10 +657,6 @@ build/release: tinygo gen-device wasi-libc $(if $(filter 1,$(USE_SYSTEM_BINARYEN
|
||||||
|
@mkdir -p build/release/tinygo/pkg/thumbv7em-unknown-unknown-eabi-cortex-m4
|
||||||
|
@echo copying source files
|
||||||
|
@cp -p build/tinygo$(EXE) build/release/tinygo/bin
|
||||||
|
-ifneq ($(USE_SYSTEM_BINARYEN),1)
|
||||||
|
- @cp -p build/wasm-opt$(EXE) build/release/tinygo/bin
|
||||||
|
-endif
|
||||||
|
- @cp -p $(abspath $(CLANG_SRC))/lib/Headers/*.h build/release/tinygo/lib/clang/include
|
||||||
|
@cp -rp lib/CMSIS/CMSIS/Include build/release/tinygo/lib/CMSIS/CMSIS
|
||||||
|
@cp -rp lib/CMSIS/README.md build/release/tinygo/lib/CMSIS
|
||||||
|
@cp -rp lib/macos-minimal-sdk/* build/release/tinygo/lib/macos-minimal-sdk
|
||||||
|
@@ -705,8 +695,7 @@ endif
|
||||||
|
@cp -rp lib/picolibc/newlib/libm/common build/release/tinygo/lib/picolibc/newlib/libm
|
||||||
|
@cp -rp lib/picolibc-stdio.c build/release/tinygo/lib
|
||||||
|
@cp -rp lib/wasi-libc/sysroot build/release/tinygo/lib/wasi-libc/sysroot
|
||||||
|
- @cp -rp llvm-project/compiler-rt/lib/builtins build/release/tinygo/lib/compiler-rt-builtins
|
||||||
|
- @cp -rp llvm-project/compiler-rt/LICENSE.TXT build/release/tinygo/lib/compiler-rt-builtins
|
||||||
|
+ @cp -rp lib/compiler-rt-builtins build/release/tinygo/lib/compiler-rt-builtins
|
||||||
|
@cp -rp src build/release/tinygo/src
|
||||||
|
@cp -rp targets build/release/tinygo/targets
|
||||||
|
./build/tinygo build-library -target=cortex-m0 -o build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0/compiler-rt compiler-rt
|
||||||
|
--
|
||||||
|
2.36.0
|
||||||
|
|
@ -0,0 +1,55 @@ |
|||||||
|
From 4ee942ccc7cdb06ee51490e9cb44ecb36b25378a Mon Sep 17 00:00:00 2001
|
||||||
|
From: =?UTF-8?q?Mustafa=20=C3=87al=C4=B1=C5=9Fkan?= <muscaln@protonmail.com>
|
||||||
|
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 479b541d..b35283c6 100644
|
||||||
|
--- a/builder/builtins.go
|
||||||
|
+++ b/builder/builtins.go
|
||||||
|
@@ -164,7 +164,7 @@ var aeabiBuiltins = []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 f1b061ae..159f90cf 100644
|
||||||
|
--- a/builder/picolibc.go
|
||||||
|
+++ b/builder/picolibc.go
|
||||||
|
@@ -27,7 +27,7 @@ var Picolibc = Library{
|
||||||
|
"-D_COMPILING_NEWLIB",
|
||||||
|
"-DHAVE_ALIAS_ATTRIBUTE",
|
||||||
|
"-DTINY_STDIO",
|
||||||
|
- "-nostdlibinc",
|
||||||
|
+ "-isystem", "@clang_include@",
|
||||||
|
"-isystem", picolibcDir + "/include",
|
||||||
|
"-I" + picolibcDir + "/tinystdio",
|
||||||
|
"-I" + headerPath,
|
||||||
|
diff --git a/compileopts/config.go b/compileopts/config.go
|
||||||
|
index b30e653e..7561b3f2 100644
|
||||||
|
--- a/compileopts/config.go
|
||||||
|
+++ b/compileopts/config.go
|
||||||
|
@@ -288,6 +288,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"),
|
||||||
|
@@ -297,7 +298,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"),
|
||||||
|
--
|
||||||
|
2.36.0
|
||||||
|
|
@ -1,64 +1,147 @@ |
|||||||
{ lib, buildGoModule, fetchFromGitHub, llvm, clang-unwrapped, lld, avrgcc |
{ stdenv |
||||||
, avrdude, openocd, gcc-arm-embedded, makeWrapper, fetchurl }: |
, lib |
||||||
|
, buildPackages |
||||||
|
, buildGoModule |
||||||
|
, fetchFromGitHub |
||||||
|
, makeWrapper |
||||||
|
, substituteAll |
||||||
|
, llvmPackages |
||||||
|
, go |
||||||
|
, libffi |
||||||
|
, zlib |
||||||
|
, ncurses |
||||||
|
, libxml2 |
||||||
|
, xar |
||||||
|
, wasi-libc |
||||||
|
, avrgcc |
||||||
|
, binaryen |
||||||
|
, avrdude |
||||||
|
, gdb |
||||||
|
, openocd |
||||||
|
}: |
||||||
|
|
||||||
let main = ./main.go; |
let |
||||||
gomod = ./go.mod; |
llvmMajor = lib.versions.major llvm.version; |
||||||
|
inherit (llvmPackages) llvm clang compiler-rt lld; |
||||||
in |
in |
||||||
|
|
||||||
buildGoModule rec { |
buildGoModule rec { |
||||||
pname = "tinygo"; |
pname = "tinygo"; |
||||||
version = "0.16.0"; |
version = "0.23.0"; |
||||||
|
|
||||||
src = fetchFromGitHub { |
src = fetchFromGitHub { |
||||||
owner = "tinygo-org"; |
owner = "tinygo-org"; |
||||||
repo = "tinygo"; |
repo = "tinygo"; |
||||||
rev = "v${version}"; |
rev = "v${version}"; |
||||||
sha256 = "063aszbsnr0myq56kms1slmrfs7m4nmg0zgh2p66lxdsifrfly7j"; |
sha256 = "sha256-YgQGAQJw9Xyw5BF2d9uZTQHfjHsu2evZGo4RV9DtStE="; |
||||||
fetchSubmodules = true; |
fetchSubmodules = true; |
||||||
}; |
}; |
||||||
|
|
||||||
overrideModAttrs = (_: { |
vendorSha256 = "sha256-fK8BlCh+1NtHW6MwW68iSIB+Sw6AK+g3y4lMyMYrXkk="; |
||||||
patches = []; |
|
||||||
preBuild = '' |
patches = [ |
||||||
rm -rf * |
./0001-Makefile.patch |
||||||
cp ${main} main.go |
|
||||||
cp ${gomod} go.mod |
(substituteAll { |
||||||
chmod +w go.mod |
src = ./0002-Add-clang-header-path.patch; |
||||||
''; |
clang_include = "${clang.cc.lib}/lib/clang/${clang.cc.version}/include"; |
||||||
}); |
}) |
||||||
|
]; |
||||||
|
|
||||||
preBuild = "cp ${gomod} go.mod"; |
checkInputs = [ avrgcc binaryen ]; |
||||||
|
nativeBuildInputs = [ go makeWrapper ]; |
||||||
|
buildInputs = [ llvm clang.cc ] |
||||||
|
++ lib.optionals stdenv.isDarwin [ zlib ncurses libffi libxml2 xar ]; |
||||||
|
|
||||||
postBuild = "make gen-device"; |
doCheck = stdenv.buildPlatform == stdenv.hostPlatform; |
||||||
|
|
||||||
vendorSha256 = "12k2gin0v7aqz5543m12yhifc0xsz26qyqra5l4c68xizvzcvkxb"; |
allowGoReference = true; |
||||||
|
tags = [ "llvm${llvmMajor}" ]; |
||||||
|
subPackages = [ "." ]; |
||||||
|
|
||||||
doCheck = false; |
# Output contains static libraries for different arm cpus |
||||||
|
# and stripping could mess up these so only strip the compiler |
||||||
|
stripDebugList = [ "bin" ]; |
||||||
|
|
||||||
prePatch = '' |
postConfigure = lib.optionalString stdenv.isDarwin '' |
||||||
sed -i s/', "-nostdlibinc"'// builder/builtins.go |
for i in vendor/tinygo.org/x/go-llvm/llvm_config_darwin*; do |
||||||
sed -i s/'"-nostdlibinc", '// compileopts/config.go builder/picolibc.go |
substituteInPlace $i --replace "curses" "ncurses" |
||||||
|
done |
||||||
''; |
''; |
||||||
|
|
||||||
subPackages = [ "." ]; |
postPatch = '' |
||||||
nativeBuildInputs = [ makeWrapper ]; |
# Copy wasi-libc, symlink seems not working |
||||||
buildInputs = [ llvm clang-unwrapped ]; |
rm -rf lib/wasi-libc/* |
||||||
propagatedBuildInputs = [ lld avrgcc avrdude openocd gcc-arm-embedded ]; |
mkdir -p lib/wasi-libc/sysroot/lib/wasm32-wasi lib/wasi-libc/sysroot/include |
||||||
|
cp -a ${wasi-libc}/lib/* lib/wasi-libc/sysroot/lib/wasm32-wasi/ |
||||||
postInstall = '' |
cp -a ${wasi-libc.dev}/include/* lib/wasi-libc/sysroot/include/ |
||||||
mkdir -p $out/share/tinygo |
|
||||||
cp -a lib src targets $out/share/tinygo |
# Borrow compiler-rt builtins from our source |
||||||
wrapProgram $out/bin/tinygo --prefix "TINYGOROOT" : "$out/share/tinygo" \ |
# See https://github.com/tinygo-org/tinygo/pull/2471 |
||||||
--prefix "PATH" : "$out/libexec/tinygo" |
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 "build/release/tinygo/bin" "$out/bin" \ |
||||||
|
--replace "build/release/" "$out/share/" |
||||||
|
|
||||||
|
# TODO: Fix mingw and darwin |
||||||
|
# Disable windows and darwin cross-compile tests |
||||||
|
sed -i "/GOOS=windows/d" Makefile |
||||||
|
sed -i "/GOOS=darwin/d" Makefile |
||||||
|
|
||||||
|
# tinygo needs versioned binaries |
||||||
mkdir -p $out/libexec/tinygo |
mkdir -p $out/libexec/tinygo |
||||||
ln -s ${clang-unwrapped}/bin/clang $out/libexec/tinygo/clang-10 |
ln -s ${lib.getBin clang.cc}/bin/clang $out/libexec/tinygo/clang-${llvmMajor} |
||||||
ln -s ${lld}/bin/lld $out/libexec/tinygo/ld.lld-10 |
ln -s ${lib.getBin lld}/bin/ld.lld $out/libexec/tinygo/ld.lld-${llvmMajor} |
||||||
ln -sf $out/bin $out/share/tinygo |
ln -s ${lib.getBin lld}/bin/wasm-ld $out/libexec/tinygo/wasm-ld-${llvmMajor} |
||||||
|
ln -s ${gdb}/bin/gdb $out/libexec/tinygo/gdb-multiarch |
||||||
|
'' + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' |
||||||
|
substituteInPlace Makefile \ |
||||||
|
--replace "./build/tinygo" "${buildPackages.tinygo}/bin/tinygo" |
||||||
|
''; |
||||||
|
|
||||||
|
preBuild = '' |
||||||
|
export HOME=$TMPDIR |
||||||
|
export GOCACHE=$TMPDIR/go-cache |
||||||
|
export GOPATH=$TMPDIR/go |
||||||
|
export PATH=$out/libexec/tinygo:$PATH |
||||||
''; |
''; |
||||||
|
|
||||||
|
postBuild = '' |
||||||
|
# Move binary |
||||||
|
mkdir -p build |
||||||
|
mv $GOPATH/bin/tinygo build/tinygo |
||||||
|
|
||||||
|
make gen-device |
||||||
|
''; |
||||||
|
|
||||||
|
checkPhase = '' |
||||||
|
runHook preCheck |
||||||
|
make smoketest XTENSA=0 |
||||||
|
runHook postCheck |
||||||
|
''; |
||||||
|
|
||||||
|
installPhase = '' |
||||||
|
runHook preInstall |
||||||
|
|
||||||
|
make build/release |
||||||
|
|
||||||
|
wrapProgram $out/bin/tinygo \ |
||||||
|
--set TINYGOROOT $out/share/tinygo \ |
||||||
|
--prefix PATH : ${lib.makeBinPath [ go avrdude openocd avrgcc binaryen ]}:$out/libexec/tinygo |
||||||
|
|
||||||
|
runHook postInstall |
||||||
|
''; |
||||||
|
|
||||||
|
disallowedReferences = [ wasi-libc ]; |
||||||
|
|
||||||
meta = with lib; { |
meta = with lib; { |
||||||
homepage = "https://tinygo.org/"; |
homepage = "https://tinygo.org/"; |
||||||
description = "Go compiler for small places"; |
description = "Go compiler for small places"; |
||||||
license = licenses.bsd3; |
license = licenses.bsd3; |
||||||
maintainers = with maintainers; [ Madouura ]; |
maintainers = with maintainers; [ Madouura muscaln ]; |
||||||
|
broken = stdenv.isDarwin; |
||||||
}; |
}; |
||||||
} |
} |
||||||
|
@ -1,14 +0,0 @@ |
|||||||
module github.com/tinygo-org/tinygo |
|
||||||
|
|
||||||
go 1.11 |
|
||||||
|
|
||||||
require ( |
|
||||||
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 |
|
||||||
github.com/chromedp/cdproto v0.0.0-20200709115526-d1f6fc58448b |
|
||||||
github.com/chromedp/chromedp v0.5.4-0.20200303084119-2bb39134ab9e |
|
||||||
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf |
|
||||||
github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892 |
|
||||||
go.bug.st/serial v1.0.0 |
|
||||||
golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2 |
|
||||||
tinygo.org/x/go-llvm v0.0.0-20201104183921-570e7a6841d9 |
|
||||||
) |
|
@ -1,18 +0,0 @@ |
|||||||
package main |
|
||||||
|
|
||||||
import ( |
|
||||||
"fmt" |
|
||||||
|
|
||||||
_ "github.com/blakesmith/ar" |
|
||||||
_ "github.com/google/shlex" |
|
||||||
_ "github.com/marcinbor85/gohex" |
|
||||||
_ "go.bug.st/serial" |
|
||||||
_ "golang.org/x/tools/go/ast/astutil" |
|
||||||
_ "golang.org/x/tools/go/ssa" |
|
||||||
_ "google.golang.org/appengine" |
|
||||||
_ "tinygo.org/x/go-llvm" |
|
||||||
) |
|
||||||
|
|
||||||
func main() { |
|
||||||
fmt.Println("vim-go") |
|
||||||
} |
|
Loading…
Reference in new issue