Go build system: reduce resulting installation sizes (#47943)

* Reduce the size of outputted go built binaries
* Remove unused import from go package
* go: remove comment from setup dependents build env
* Add back missing imports after rebase
This commit is contained in:
Alec Scott 2025-01-27 14:32:56 -05:00 committed by GitHub
parent 8ac0bd2825
commit ebc9f03dda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 28 deletions

View File

@ -9,7 +9,7 @@
import spack.phase_callbacks import spack.phase_callbacks
import spack.spec import spack.spec
import spack.util.prefix import spack.util.prefix
from spack.directives import build_system, extends from spack.directives import build_system, depends_on
from spack.multimethod import when from spack.multimethod import when
from ._checks import BuilderWithDefaults, execute_install_time_tests from ._checks import BuilderWithDefaults, execute_install_time_tests
@ -28,9 +28,7 @@ class GoPackage(spack.package_base.PackageBase):
build_system("go") build_system("go")
with when("build_system=go"): with when("build_system=go"):
# TODO: this seems like it should be depends_on, see depends_on("go", type="build")
# setup_dependent_build_environment in go for why I kept it like this
extends("go@1.14:", type="build")
@spack.builder.builder("go") @spack.builder.builder("go")
@ -73,6 +71,7 @@ class GoBuilder(BuilderWithDefaults):
def setup_build_environment(self, env): def setup_build_environment(self, env):
env.set("GO111MODULE", "on") env.set("GO111MODULE", "on")
env.set("GOTOOLCHAIN", "local") env.set("GOTOOLCHAIN", "local")
env.set("GOPATH", fs.join_path(self.pkg.stage.path, "go"))
@property @property
def build_directory(self): def build_directory(self):

View File

@ -5,8 +5,6 @@
import os import os
import re import re
from llnl.util import tty
from spack.package import * from spack.package import *
# - vanilla CentOS 7, and possibly other systems, fail a test: # - vanilla CentOS 7, and possibly other systems, fail a test:
@ -119,30 +117,8 @@ def install(self, spec, prefix):
def setup_dependent_package(self, module, dependent_spec): def setup_dependent_package(self, module, dependent_spec):
"""Called before go modules' build(), install() methods. """Called before go modules' build(), install() methods.
In most cases, extensions will only need to set GOPATH and use go::
env['GOPATH'] = self.source_path + ':' + env['GOPATH']
go('get', '<package>', env=env) go('get', '<package>', env=env)
install_tree('bin', prefix.bin) install_tree('bin', prefix.bin)
""" """
# Add a go command/compiler for extensions # Add a go command/compiler for extensions
module.go = self.spec["go"].command module.go = self.spec["go"].command
def generate_path_components(self, dependent_spec):
if os.environ.get("GOROOT", False):
tty.warn("GOROOT is set, this is not recommended")
# Set to include paths of dependencies
path_components = [dependent_spec.prefix]
for d in dependent_spec.traverse():
if d.package.extends(self.spec):
path_components.append(d.prefix)
return ":".join(path_components)
def setup_dependent_build_environment(self, env, dependent_spec):
# This *MUST* be first, this is where new code is installed
env.prepend_path("GOPATH", self.generate_path_components(dependent_spec))
def setup_dependent_run_environment(self, env, dependent_spec):
# Allow packages to find this when using module files
env.prepend_path("GOPATH", self.generate_path_components(dependent_spec))