Browse Source

all: support Arduino in the compiler driver

This makes sure the compiler itself can build/link an ELF file that
works on an Arduino.
pull/6/head
Ayke van Laethem 6 years ago
parent
commit
914cd56ca5
No known key found for this signature in database GPG Key ID: E97FF5335DFDFDED
  1. 3
      main.go
  2. 7
      target.go
  3. 4
      targets/arduino.json

3
main.go

@ -89,7 +89,8 @@ func Compile(pkgName, runtimePath, outpath, target string, printIR, dumpSSA bool
// Link the object file with the system compiler.
executable := filepath.Join(dir, "main")
cmd := exec.Command("cc", "-o", executable, objfile)
args := append(spec.PreLinkArgs, "-o", executable, objfile)
cmd := exec.Command(spec.Linker, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()

7
target.go

@ -14,8 +14,10 @@ import (
// https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/struct.TargetOptions.html
// https://github.com/shepmaster/rust-arduino-blink-led-no-core-with-cargo/blob/master/blink/arduino.json
type TargetSpec struct {
Triple string `json:"llvm-target"`
BuildTags []string `json:"build-tags"`
Triple string `json:"llvm-target"`
BuildTags []string `json:"build-tags"`
Linker string `json:"linker"`
PreLinkArgs []string `json:"pre-link-args"`
}
// Load a target specification
@ -23,6 +25,7 @@ func LoadTarget(target string) (*TargetSpec, error) {
spec := &TargetSpec{
Triple: target,
BuildTags: []string{runtime.GOOS, runtime.GOARCH},
Linker: "cc",
}
// See whether there is a target specification for this target (e.g.

4
targets/arduino.json

@ -1,4 +1,6 @@
{
"llvm-target": "avr-atmel-none",
"build-tags": ["avr", "avr8", "atmega", "atmega328p", "js", "wasm"]
"build-tags": ["avr", "avr8", "atmega", "atmega328p", "js", "wasm"],
"linker": "avr-gcc",
"pre-link-args": ["-nostdlib", "-T", "avr.ld", "-Wl,--gc-sections", "avr.S"]
}

Loading…
Cancel
Save