Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
445fd37
main: update version for beginning of v0.14 development cycle
niaow Apr 13, 2020
f66492a
Fix return address in scheduler
Apr 22, 2020
fc4857e
runtime: avoid recursion in printuint64 function
aykevl Apr 4, 2020
9342e73
builder: fix picolibc include path
aykevl Apr 13, 2020
6389e45
all: replace ReadRegister with AsmFull inline assembly
aykevl Apr 6, 2020
23e88bf
arm: allow nesting in DisableInterrupts and EnableInterrupts
aykevl Apr 6, 2020
d0b2585
main: update go-llvm to fix macOS build problem
aykevl May 3, 2020
904fa85
transform: fix debug information in func lowering pass
aykevl May 3, 2020
8ce3cfa
flash: fix getDefaultPort() fails on Windows locales such as Japan
sago35 May 7, 2020
5ed0f67
sam: fix ROM / RAM size on atsamd51j20
sago35 May 7, 2020
171d0fe
implement mutex blocking
niaow Jan 27, 2020
ccd79ee
add sync.Cond
niaow Jan 27, 2020
ae2cbbf
internal/task: fix nil panic in (*internal/task.Stack).Pop
niaow Mar 17, 2020
afc6bd5
sync: add WaitGroup
niaow Mar 17, 2020
7801921
testdata: replace fake waitgroup in channel.go with sync.WaitGroup
niaow Mar 17, 2020
c54e1cc
sync: modify sync.Cond
niaow Mar 26, 2020
b481519
testdata, sync: add sync.Mutex test to testdata/coroutines.go
niaow Mar 27, 2020
00f3a65
machine/arduino-nano33: use (U)SB flag to ensure that device can be f…
deadprogram May 9, 2020
01f5c1d
machine/arduino-nano33: remove (d)ebug flag to reduce console noise w…
deadprogram May 9, 2020
acdaa72
runtime: fix compilation errors when using gc.extalloc
cornelk May 11, 2020
1461563
testdata: fix formatting
cornelk May 11, 2020
7e64bc8
runtime: add cap and len support for chans
cornelk May 11, 2020
2c71f08
reflect: add Cap and Len support for map and chan
cornelk May 11, 2020
6b89404
avr: use standard pin numbering
aykevl May 10, 2020
e907db1
os: add Args and stub it with mock data
cornelk May 11, 2020
6bcb40f
os: implement virtual filesystem support
aykevl Mar 30, 2020
aa40ddc
ci: do not install the SiFive toolchain
aykevl May 13, 2020
b5f028e
ci: build .deb files along with .tar.gz files for Debian
aykevl May 12, 2020
38fc340
sam: return an error when an incorrect PWM pin is used
aykevl May 11, 2020
473644d
internal/bytealg: reimplement bytealg in pure Go
niaow Apr 7, 2020
29ca114
call scheduler from resume
bradleypeabody May 12, 2020
76fb3bd
compileopts: improve error reporting of unsupported flags
cebernardi May 16, 2020
b9fd6ce
build: add webhook notifier orb for circleci
deadprogram May 13, 2020
726d735
cgo: Add LDFlags support
racerxdl May 20, 2020
424d775
build: remove CircleCI orb, now using different integration
deadprogram May 21, 2020
da505a6
avr: unify GPIO pin/port code
aykevl May 14, 2020
dda576e
avr: add support for PinInputPullup
aykevl May 14, 2020
95f509b
wasm test suite (#1116)
bradleypeabody May 23, 2020
3c55689
runtime: refactor time handling
aykevl May 21, 2020
9f4459c
arm: make FPU configuraton consistent
aykevl May 12, 2020
e69131c
nrf: expose the RAM base address
aykevl May 24, 2020
67ac4fd
nrf: add microbit-s110v8 target
aykevl May 24, 2020
4918395
added test for wasm log output
bradleypeabody May 23, 2020
2a98433
builder: move Go version code to goenv package
aykevl May 4, 2020
ab2a81c
main: move TinyGo version to goenv
aykevl May 20, 2020
bde73fc
main: fix test subcommand
aykevl May 4, 2020
35015a7
loader: merge roots from both Go and TinyGo in a cached directory
aykevl Mar 5, 2020
4ca2d3f
loader: load packages using Go modules
aykevl May 4, 2020
c248418
compiler: fix a few crashes due to named types
aykevl May 26, 2020
19c7965
nrf: add support for pin change interrupts
aykevl Jan 13, 2020
c72f9eb
sam: add support for pin change interrupts
aykevl Jan 15, 2020
1570ada
transform: do not special-case zero or one implementations of a metho…
aykevl May 27, 2020
734613c
transform: introduce check for method calls on nil interfaces
aykevl May 27, 2020
fed433c
compiler: add support for atomic operations
aykevl May 15, 2020
5c8d4e5
sam: add support for pin change interrupts (samd5x)
sago35 May 12, 2020
b92fad8
sam: fix register access for interrupts pins in samd51 (#1141)
sago35 May 30, 2020
5e2a802
main: use auto-retry (up to 10 seconds) to locate MSD for UF2 and HEX…
deadprogram May 23, 2020
bcbc241
main: improve/simplify auto-retry to locate MSD for UF2 and HEX flashing
deadprogram May 27, 2020
0e73790
Dockerfile: avoid duplicate LLVM apt line
aykevl May 30, 2020
3c31a31
builder: use newer version of gohex
aykevl May 31, 2020
72064e1
WIP flash: fix touchSerialPortAt1200bps on windows
sago35 May 7, 2020
9712297
Add SAMD51 pins
sago35 Jun 3, 2020
40afeea
Add SAMD51 ADC settings
sago35 May 24, 2020
f103e91
Add SAMD51 pin change interrupt settings
sago35 Jun 3, 2020
64d51b2
Extend SAMD51 pinPadMapping
sago35 May 27, 2020
0c880ec
Standardize SAMD51 UART settings (#1155)
sago35 Jun 5, 2020
c5a8967
Seeed WioTerminal support (#1124)
sago35 Jun 6, 2020
d61d5d7
Zero PLIC threshold value at startup
Jun 7, 2020
2396c22
risc-v: add support for 64-bit RISC-V CPUs
yannishuber Jun 8, 2020
d3f5b51
compiler: add support for custom code model
yannishuber Jun 8, 2020
e2c55e3
gen-device-svd: fix lowercase cluster name
yannishuber Jun 8, 2020
9ed5eae
cgo: use scanner.Error in libclang
aykevl Jun 8, 2020
169d5f1
nrf: fix bug in SPI.Tx
aykevl Jun 8, 2020
4e4b595
nrf: support debugging the PCA10056
aykevl Jun 8, 2020
4321923
compiler/runtime: move the channel blocked list onto the stack
niaow May 30, 2020
2281b6a
machine/hifive1b: remove extra println left in by mistake
deadprogram Jun 9, 2020
4d1d0c2
main: go mod tidy
aykevl Jun 10, 2020
e2bf7bb
device: add new cross-arch Asm and AsmFull functions
aykevl Jun 14, 2020
e86ca20
runtime/interrupt: add cross-chip disable/restore interrupt support
aykevl Jun 14, 2020
cb504e3
added pygamer to smoketest
APDevice Jun 18, 2020
697cb18
added pygamer to board
APDevice Jun 18, 2020
0478dd5
Adding Board: PyGamer
APDevice Jun 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ commands:
sudo tar -C /usr/local -xf node-v10.15.1-linux-x64.tar.xz
sudo ln -s /usr/local/node-v10.15.1-linux-x64/bin/node /usr/bin/node
rm node-v10.15.1-linux-x64.tar.xz
install-chrome:
steps:
- run:
name: "Install Chrome"
command: |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
llvm-source-linux:
steps:
- restore_cache:
Expand Down Expand Up @@ -71,6 +78,7 @@ commands:
- apt-dependencies:
llvm: "<<parameters.llvm>>"
- install-node
- install-chrome
- restore_cache:
keys:
- go-cache-v2-{{ checksum "go.mod" }}-{{ .Environment.CIRCLE_PREVIOUS_BUILD_NUM }}
Expand All @@ -88,6 +96,7 @@ commands:
- run: go test -v -tags=llvm<<parameters.llvm>> ./cgo ./compileopts ./interp ./transform .
- run: make gen-device -j4
- run: make smoketest
- run: make wasmtest
- save_cache:
key: go-cache-v2-{{ checksum "go.mod" }}-{{ .Environment.CIRCLE_BUILD_NUM }}
paths:
Expand Down Expand Up @@ -204,13 +213,21 @@ commands:
- run:
name: "Test TinyGo"
command: make test
- run:
name: "Install fpm"
command: |
sudo apt-get install ruby ruby-dev
sudo gem install --no-document fpm
- run:
name: "Build TinyGo release"
command: |
make release -j3
make release deb -j3
cp -p build/release.tar.gz /tmp/tinygo.linux-amd64.tar.gz
cp -p build/release.deb /tmp/tinygo_amd64.deb
- store_artifacts:
path: /tmp/tinygo.linux-amd64.tar.gz
- store_artifacts:
path: /tmp/tinygo_amd64.deb
- save_cache:
key: go-cache-v2-{{ checksum "go.mod" }}-{{ .Environment.CIRCLE_BUILD_NUM }}
paths:
Expand Down Expand Up @@ -294,11 +311,6 @@ commands:
tar -C /usr/local/opt -xf /tmp/tinygo.darwin-amd64.tar.gz
ln -s /usr/local/opt/tinygo/bin/tinygo /usr/local/bin/tinygo
tinygo version
- run:
name: "Download SiFive GNU toolchain"
command: |
curl -O https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.2.0-2019.05.3-x86_64-apple-darwin.tar.gz
sudo tar -C /usr/local --strip-components=1 -xf riscv64-unknown-elf-gcc-8.2.0-2019.05.3-x86_64-apple-darwin.tar.gz
- run: make smoketest AVR=0
- save_cache:
key: go-cache-macos-v2-{{ checksum "go.mod" }}-{{ .Environment.CIRCLE_BUILD_NUM }}
Expand Down
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ COPY --from=tinygo-base /go/bin/tinygo /go/bin/tinygo
COPY --from=tinygo-base /tinygo/src /tinygo/src
COPY --from=tinygo-base /tinygo/targets /tinygo/targets

RUN wget -O- https://apt.llvm.org/llvm-snapshot.gpg.key| apt-key add - && \
echo "deb http://apt.llvm.org/buster/ llvm-toolchain-buster-10 main" >> /etc/apt/sources.list && \
apt-get update && \
apt-get install -y libllvm10 lld-10
RUN apt-get install -y libllvm10 lld-10

# tinygo-avr stage installs the needed dependencies to compile TinyGo programs for AVR microcontrollers.
FROM tinygo-base AS tinygo-avr
Expand Down
28 changes: 24 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ tinygo-test:
.PHONY: smoketest
smoketest:
$(TINYGO) version
# test all examples
# test all examples (except pwm)
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/adc
Expand All @@ -192,7 +192,7 @@ smoketest:
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/blinky2
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/button
@$(MD5SUM) test.hex
@$(MD5SUM) test.
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/button2
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/echo
Expand All @@ -203,7 +203,7 @@ smoketest:
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=microbit examples/microbit-blink
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/pwm
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/pininterrupt
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/serial
@$(MD5SUM) test.hex
Expand Down Expand Up @@ -231,6 +231,8 @@ smoketest:
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=microbit examples/echo
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=microbit-s110v8 examples/echo
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=nrf52840-mdk examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pca10031 examples/blinky1
Expand Down Expand Up @@ -291,11 +293,17 @@ smoketest:
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=reelboard-s140v7 examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=wioterminal examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pygamer examples/blinky1
@$(MD5SUM) test.hex
ifneq ($(AVR), 0)
$(TINYGO) build -size short -o test.hex -target=atmega1284p examples/serial
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=arduino examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=arduino examples/pwm
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=arduino -scheduler=tasks examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=arduino-nano examples/blinky1
Expand All @@ -310,7 +318,10 @@ endif
$(TINYGO) build -o wasm.wasm -target=wasm examples/wasm/export
$(TINYGO) build -o wasm.wasm -target=wasm examples/wasm/main

release: tinygo gen-device wasi-libc
wasmtest:
$(GO) test ./tests/wasm

build/release: tinygo gen-device wasi-libc
@mkdir -p build/release/tinygo/bin
@mkdir -p build/release/tinygo/lib/clang/include
@mkdir -p build/release/tinygo/lib/CMSIS/CMSIS
Expand Down Expand Up @@ -345,4 +356,13 @@ release: tinygo gen-device wasi-libc
./build/tinygo build-library -target=armv6m-none-eabi -o build/release/tinygo/pkg/armv6m-none-eabi/picolibc.a picolibc
./build/tinygo build-library -target=armv7m-none-eabi -o build/release/tinygo/pkg/armv7m-none-eabi/picolibc.a picolibc
./build/tinygo build-library -target=armv7em-none-eabi -o build/release/tinygo/pkg/armv7em-none-eabi/picolibc.a picolibc

release: build/release
tar -czf build/release.tar.gz -C build/release tinygo

deb: build/release
@mkdir -p build/release-deb/usr/local/bin
@mkdir -p build/release-deb/usr/local/lib
cp -ar build/release/tinygo build/release-deb/usr/local/lib/tinygo
ln -sf ../lib/tinygo/bin/tinygo build/release-deb/usr/local/bin/tinygo
fpm -f -s dir -t deb -n tinygo -v $(shell grep "const Version = " goenv/version.go | awk '{print $$NF}') -m '@tinygo-org' --description='TinyGo is a Go compiler for small places.' --license='BSD 3-Clause' --url=https://tinygo.org/ --deb-changelog CHANGELOG.md -p build/release.deb -C ./build/release-deb
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ See the [getting started instructions](https://tinygo.org/getting-started/) for

You can compile TinyGo programs for microcontrollers, WebAssembly and Linux.

The following 32 microcontroller boards are currently supported:
The following 33 microcontroller boards are currently supported:

* [Adafruit Circuit Playground Bluefruit](https://www.adafruit.com/product/4333)
* [Adafruit Circuit Playground Express](https://www.adafruit.com/product/3333)
Expand Down Expand Up @@ -72,6 +72,7 @@ The following 32 microcontroller boards are currently supported:
* [Particle Xenon](https://docs.particle.io/datasheets/discontinued/xenon-datasheet/)
* [Phytec reel board](https://www.phytec.eu/product-eu/internet-of-things/reelboard/)
* [PineTime DevKit](https://www.pine64.org/pinetime/)
* [Seeed Wio Terminal](https://www.seeedstudio.com/Wio-Terminal-p-4509.html)
* [SiFIve HiFive1](https://www.sifive.com/boards/hifive1)
* [ST Micro "Nucleo F103RB"](https://www.st.com/en/evaluation-tools/nucleo-f103rb.html)
* [ST Micro STM32F103XX "Bluepill"](http://wiki.stm32duino.com/index.php?title=Blue_Pill)
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
script: |
export PATH="$PATH:./llvm-build/bin:/c/Program Files/qemu"
unset GOROOT
make release -j4
make build/release -j4
- publish: $(System.DefaultWorkingDirectory)/build/release/tinygo
displayName: Publish zip as artifact
artifact: tinygo
Expand Down
6 changes: 5 additions & 1 deletion builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(stri
if err != nil {
return err
}
mod, extraFiles, errs := compiler.Compile(pkgName, machine, config)
mod, extraFiles, extraLDFlags, errs := compiler.Compile(pkgName, machine, config)
if errs != nil {
return newMultiError(errs)
}
Expand Down Expand Up @@ -187,6 +187,10 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(stri
ldflags = append(ldflags, outpath)
}

if len(extraLDFlags) > 0 {
ldflags = append(ldflags, extraLDFlags...)
}

// Link the object files together.
err = link(config.Target.Linker, ldflags...)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) {
if goroot == "" {
return nil, errors.New("cannot locate $GOROOT, please set it manually")
}
major, minor, err := getGorootVersion(goroot)
major, minor, err := goenv.GetGorootVersion(goroot)
if err != nil {
return nil, fmt.Errorf("could not read version from GOROOT (%v): %v", goroot, err)
}
Expand Down
58 changes: 0 additions & 58 deletions builder/env.go
Original file line number Diff line number Diff line change
@@ -1,71 +1,13 @@
package builder

import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"sort"
"strings"
)

// getGorootVersion returns the major and minor version for a given GOROOT path.
// If the goroot cannot be determined, (0, 0) is returned.
func getGorootVersion(goroot string) (major, minor int, err error) {
s, err := GorootVersionString(goroot)
if err != nil {
return 0, 0, err
}

if s == "" || s[:2] != "go" {
return 0, 0, errors.New("could not parse Go version: version does not start with 'go' prefix")
}

parts := strings.Split(s[2:], ".")
if len(parts) < 2 {
return 0, 0, errors.New("could not parse Go version: version has less than two parts")
}

// Ignore the errors, we don't really handle errors here anyway.
var trailing string
n, err := fmt.Sscanf(s, "go%d.%d%s", &major, &minor, &trailing)
if n == 2 && err == io.EOF {
// Means there were no trailing characters (i.e., not an alpha/beta)
err = nil
}
if err != nil {
return 0, 0, fmt.Errorf("failed to parse version: %s", err)
}
return
}

// GorootVersionString returns the version string as reported by the Go
// toolchain for the given GOROOT path. It is usually of the form `go1.x.y` but
// can have some variations (for beta releases, for example).
func GorootVersionString(goroot string) (string, error) {
if data, err := ioutil.ReadFile(filepath.Join(
goroot, "src", "runtime", "internal", "sys", "zversion.go")); err == nil {

r := regexp.MustCompile("const TheVersion = `(.*)`")
matches := r.FindSubmatch(data)
if len(matches) != 2 {
return "", errors.New("Invalid go version output:\n" + string(data))
}

return string(matches[1]), nil

} else if data, err := ioutil.ReadFile(filepath.Join(goroot, "VERSION")); err == nil {
return string(data), nil

} else {
return "", err
}
}

// getClangHeaderPath returns the path to the built-in Clang headers. It tries
// multiple locations, which should make it find the directory when installed in
// various ways.
Expand Down
2 changes: 1 addition & 1 deletion builder/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (l *Library) Load(target string) (path string, err error) {
// Precalculate the flags to the compiler invocation.
args := append(l.cflags(), "-c", "-Oz", "-g", "-ffunction-sections", "-fdata-sections", "-Wno-macro-redefined", "--target="+target, "-fdebug-prefix-map="+dir+"="+remapDir)
if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") {
args = append(args, "-fshort-enums", "-fomit-frame-pointer")
args = append(args, "-fshort-enums", "-fomit-frame-pointer", "-mfloat-abi=soft")
}
if strings.HasPrefix(target, "riscv32-") {
args = append(args, "-march=rv32imac", "-mabi=ilp32", "-fforce-enable-int128")
Expand Down
3 changes: 1 addition & 2 deletions builder/objcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ func objcopy(infile, outfile string) error {
if err != nil {
return objcopyError{"failed to create .hex file", err}
}
mem.DumpIntelHex(f, 16) // TODO: handle error
return nil
return mem.DumpIntelHex(f, 16)
default:
panic("unreachable")
}
Expand Down
2 changes: 1 addition & 1 deletion builder/picolibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var Picolibc = Library{
name: "picolibc",
cflags: func() []string {
picolibcDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib/picolibc/newlib/libc")
return []string{"-Werror", "-Wall", "-std=gnu11", "-D_COMPILING_NEWLIB", "--sysroot=" + picolibcDir, "-I" + picolibcDir + "/tinystdio", "-I" + goenv.Get("TINYGOROOT") + "/lib/picolibc-include"}
return []string{"-Werror", "-Wall", "-std=gnu11", "-D_COMPILING_NEWLIB", "-nostdlibinc", "-Xclang", "-internal-isystem", "-Xclang", picolibcDir + "/include", "-I" + picolibcDir + "/tinystdio", "-I" + goenv.Get("TINYGOROOT") + "/lib/picolibc-include"}
},
sourceDir: "lib/picolibc/newlib/libc",
sources: func(target string) []string {
Expand Down
20 changes: 17 additions & 3 deletions cgo/cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type cgoPackage struct {
elaboratedTypes map[string]*elaboratedTypeInfo
enums map[string]enumInfo
anonStructNum int
ldflags []string
}

// constantInfo stores some information about a CGo constant found by libclang
Expand Down Expand Up @@ -156,7 +157,7 @@ typedef unsigned long long _Cgo_ulonglong;
// newly created *ast.File that should be added to the list of to-be-parsed
// files. If there is one or more error, it returns these in the []error slice
// but still modifies the AST.
func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string) (*ast.File, []error) {
func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string) (*ast.File, []string, []error) {
p := &cgoPackage{
dir: dir,
fset: fset,
Expand All @@ -183,7 +184,7 @@ func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string
// Find the absolute path for this package.
packagePath, err := filepath.Abs(fset.File(files[0].Pos()).Name())
if err != nil {
return nil, []error{
return nil, nil, []error{
scanner.Error{
Pos: fset.Position(files[0].Pos()),
Msg: "cgo: cannot find absolute path: " + err.Error(), // TODO: wrap this error
Expand Down Expand Up @@ -359,6 +360,19 @@ func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string
}
makePathsAbsolute(flags, packagePath)
cflags = append(cflags, flags...)
case "LDFLAGS":
flags, err := shlex.Split(value)
if err != nil {
// TODO: find the exact location where the error happened.
p.addErrorAfter(comment.Slash, comment.Text[:lineStart+colon+1], "failed to parse flags in #cgo line: "+err.Error())
continue
}
if err := checkLinkerFlags(name, flags); err != nil {
p.addErrorAfter(comment.Slash, comment.Text[:lineStart+colon+1], err.Error())
continue
}
makePathsAbsolute(flags, packagePath)
p.ldflags = append(p.ldflags, flags...)
default:
startPos := strings.LastIndex(line[4:colon], name) + 4
p.addErrorAfter(comment.Slash, comment.Text[:lineStart+startPos], "invalid #cgo line: "+name)
Expand Down Expand Up @@ -412,7 +426,7 @@ func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string
// Print the newly generated in-memory AST, for debugging.
//ast.Print(fset, p.generated)

return p.generated, p.errors
return p.generated, p.ldflags, p.errors
}

// makePathsAbsolute converts some common path compiler flags (-I, -L) from
Expand Down
2 changes: 1 addition & 1 deletion cgo/cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCGo(t *testing.T) {
}

// Process the AST with CGo.
cgoAST, cgoErrors := Process([]*ast.File{f}, "testdata", fset, cflags)
cgoAST, _, cgoErrors := Process([]*ast.File{f}, "testdata", fset, cflags)

// Check the AST for type errors.
var typecheckErrors []error
Expand Down
6 changes: 3 additions & 3 deletions cgo/libclang.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ func tinygo_clang_globals_visitor(c, parent C.GoCXCursor, client_data C.CXClient
}
value := source[len(name):]
// Try to convert this #define into a Go constant expression.
expr, err := parseConst(pos+token.Pos(len(name)), p.fset, value)
if err != nil {
p.errors = append(p.errors, err)
expr, scannerError := parseConst(pos+token.Pos(len(name)), p.fset, value)
if scannerError != nil {
p.errors = append(p.errors, *scannerError)
}
if expr != nil {
// Parsing was successful.
Expand Down
Loading