Skip to content

Use build_settings and transitions instead of aspect for cross-compilation #2219

@jayconrod

Description

@jayconrod

rules_go provides two ways to cross-compile code:

  1. Users may set a target platform using --platforms on the command line. This selects a toolchain whose "default platform" is the target platform. We declare a separate go_toolchain and toolchain for each supported platform (even though the toolchains include the same files) to make this work. This mechanism generally works well.
  2. Users may set goos, goarch and other attributes on go_binary and go_test. Both rules use an aspect that creates a second graph of actions if goos, goarch and other attributes are different than the default. This mechanism the the source of a lot of problems. In particular, select expressions (used for platform-specific dependencies) do not work because select is applied before analysis.

Recent versions of Bazel support Starlark Build Configurations, which give users and Starlark rule authors much greater control over configuration transitions. We should use this functionality to remove the aspect. We may also be able to simplify toolchain declarations.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions