compiler: pass -cflags and -ldflags to tinygo CLI command
Signed-off-by: Ron Evans <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
8734732d0c
коммит
cb648d8ae1
2 изменённых файлов: 20 добавлений и 1 удалений
|
@ -32,7 +32,8 @@ func init() {
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Triple string // LLVM target triple, e.g. x86_64-unknown-linux-gnu (empty string means default)
|
Triple string // LLVM target triple, e.g. x86_64-unknown-linux-gnu (empty string means default)
|
||||||
GC string // garbage collection strategy
|
GC string // garbage collection strategy
|
||||||
CFlags []string // flags to pass to cgo
|
CFlags []string // cflags to pass to cgo
|
||||||
|
LDFlags []string // ldflags to pass to cgo
|
||||||
DumpSSA bool // dump Go SSA, for compiler debugging
|
DumpSSA bool // dump Go SSA, for compiler debugging
|
||||||
Debug bool // add debug symbols for gdb
|
Debug bool // add debug symbols for gdb
|
||||||
RootDir string // GOROOT for TinyGo
|
RootDir string // GOROOT for TinyGo
|
||||||
|
|
18
main.go
18
main.go
|
@ -34,6 +34,8 @@ type BuildConfig struct {
|
||||||
debug bool
|
debug bool
|
||||||
printSizes string
|
printSizes string
|
||||||
initInterp bool
|
initInterp bool
|
||||||
|
cFlags []string
|
||||||
|
ldFlags []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function for Compiler object.
|
// Helper function for Compiler object.
|
||||||
|
@ -41,10 +43,16 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
|
||||||
if config.gc == "" && spec.GC != "" {
|
if config.gc == "" && spec.GC != "" {
|
||||||
config.gc = spec.GC
|
config.gc = spec.GC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Append command line passed CFlags and LDFlags
|
||||||
|
spec.CFlags = append(spec.CFlags, config.cFlags...)
|
||||||
|
spec.LDFlags = append(spec.LDFlags, config.ldFlags...)
|
||||||
|
|
||||||
compilerConfig := compiler.Config{
|
compilerConfig := compiler.Config{
|
||||||
Triple: spec.Triple,
|
Triple: spec.Triple,
|
||||||
GC: config.gc,
|
GC: config.gc,
|
||||||
CFlags: spec.CFlags,
|
CFlags: spec.CFlags,
|
||||||
|
LDFlags: spec.LDFlags,
|
||||||
Debug: config.debug,
|
Debug: config.debug,
|
||||||
DumpSSA: config.dumpSSA,
|
DumpSSA: config.dumpSSA,
|
||||||
RootDir: sourceDir(),
|
RootDir: sourceDir(),
|
||||||
|
@ -497,6 +505,8 @@ func main() {
|
||||||
ocdOutput := flag.Bool("ocd-output", false, "print OCD daemon output during debug")
|
ocdOutput := flag.Bool("ocd-output", false, "print OCD daemon output during debug")
|
||||||
initInterp := flag.Bool("initinterp", true, "enable/disable partial evaluator of generated IR")
|
initInterp := flag.Bool("initinterp", true, "enable/disable partial evaluator of generated IR")
|
||||||
port := flag.String("port", "/dev/ttyACM0", "flash port")
|
port := flag.String("port", "/dev/ttyACM0", "flash port")
|
||||||
|
cFlags := flag.String("cflags", "", "additional cflags for compiler")
|
||||||
|
ldFlags := flag.String("ldflags", "", "additional ldflags for linker")
|
||||||
|
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
fmt.Fprintln(os.Stderr, "No command-line arguments supplied.")
|
fmt.Fprintln(os.Stderr, "No command-line arguments supplied.")
|
||||||
|
@ -516,6 +526,14 @@ func main() {
|
||||||
initInterp: *initInterp,
|
initInterp: *initInterp,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *cFlags != "" {
|
||||||
|
config.cFlags = strings.Split(*cFlags, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
if *ldFlags != "" {
|
||||||
|
config.ldFlags = strings.Split(*ldFlags, " ")
|
||||||
|
}
|
||||||
|
|
||||||
os.Setenv("CC", "clang -target="+*target)
|
os.Setenv("CC", "clang -target="+*target)
|
||||||
|
|
||||||
switch command {
|
switch command {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче