Skip to content

Commit

Permalink
to support cross compile
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK committed Feb 19, 2024
1 parent ff91fc0 commit 962457f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions builder/imports/golang.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from builder.core.fetch import fetch_and_extract, mirror_package
from builder.core.project import Import
import builder.core.util as util
from builder.core.host import current_platform

URLs = {
'linux-armv6': 'https://go.dev/dl/go1.21.5.linux-armv6l.tar.gz',
Expand Down Expand Up @@ -65,16 +66,25 @@ def install(self, env):
target, install_dir))

sh.mkdir(install_dir)
url = URLs[target]
if cross_compile:
# If cross compile using the go execuble for current platform instead to codegen
url = URLs[current_platform()]
else:
url = URLs[target]
ext = '.tar.gz' if url.endswith('.tar.gz') else '.zip'
filename = '{}/golang{}'.format(install_dir, ext)
print('Downloading {}'.format(url))
fetch_and_extract(url, filename, install_dir)
os.remove(filename)

# Set PATH
go_path = '{}/go/bin'.format(install_dir)
sh.setenv('PATH', '{}{}{}'.format(go_path, os.pathsep, sh.getenv('PATH')))
if cross_compile:
# Path to go binary
env.variables['go_path'] = "/work/"+str(Path(os.path.join(install_dir, 'go/bin')
).relative_to(env.root_dir))
else:
# export the PATH directly if not cross compile.
env.variables['go_path'] = '{}/go/bin'.format(install_dir)

self.installed = True

Expand Down

0 comments on commit 962457f

Please sign in to comment.