main: fix linker script includes when running outside TINYGOROOT

This commit adds the TinyGo root directory (`TINYGOROOT`) to the linker
script `-L` search path, so that linker scripts can be found when
running `tinygo` outside of the TinyGo root.

This was already working before when using an external linker by setting
the working directory, but this is not possible when using the internal
linker. However, by adding the root directory to the linker search path
(`-L`), it can now find these linker scripts.

fixes #265
This commit is contained in:
Ayke van Laethem
2019-04-16 15:49:31 +02:00
committed by Ron Evans
parent f1aea13c51
commit 5b34713d41
3 changed files with 5 additions and 7 deletions
+3 -3
View File
@@ -191,7 +191,7 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
// Prepare link command.
executable := filepath.Join(dir, "main")
tmppath := executable // final file
ldflags := append(spec.LDFlags, "-o", executable, objfile)
ldflags := append(spec.LDFlags, "-o", executable, objfile, "-L", sourceDir())
if spec.RTLib == "compiler-rt" {
ldflags = append(ldflags, librt)
}
@@ -229,9 +229,9 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
// Link the object files together.
if linker, ok := commands[spec.Linker]; ok {
err = Link(sourceDir(), linker, ldflags...)
err = Link(linker, ldflags...)
} else {
err = Link(sourceDir(), spec.Linker, ldflags...)
err = Link(spec.Linker, ldflags...)
}
if err != nil {
return &commandError{"failed to link", executable, err}