Skip to content

Commit

Permalink
Cleanup binary extension computation (#4033)
Browse files Browse the repository at this point in the history
**What type of PR is this?**
Starlark cleanup/perf improvement

**What does this PR do? Why is it needed?**
We only need the extension for binary actions, not all go-related
actions. Remove them from the context.

**Which issues(s) does this PR fix?**

Fixes #

**Other notes for review**
  • Loading branch information
dzbarsky authored Aug 12, 2024
1 parent 56d415d commit c419453
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
9 changes: 6 additions & 3 deletions go/private/actions/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
load(
"//go/private:common.bzl",
"ARCHIVE_EXTENSION",
"goos_to_extension",
"goos_to_shared_extension",
"has_shared_lib_extension",
)
load(
Expand All @@ -40,14 +42,15 @@ def emit_binary(

archive = go.archive(go, source)
if not executable:
extension = go.exe_extension
if go.mode.link == LINKMODE_C_SHARED:
name = "lib" + name # shared libraries need a "lib" prefix in their name
extension = go.shared_extension
extension = goos_to_shared_extension(go.mode.goos)
elif go.mode.link == LINKMODE_C_ARCHIVE:
extension = ARCHIVE_EXTENSION
elif go.mode.link == LINKMODE_PLUGIN:
extension = go.shared_extension
extension = goos_to_shared_extension(go.mode.goos)
else:
extension = goos_to_extension(go.mode.goos)
executable = go.declare_file(go, path = name, ext = extension)
go.link(
go,
Expand Down
4 changes: 0 additions & 4 deletions go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ load(
"COVERAGE_OPTIONS_DENYLIST",
"GO_TOOLCHAIN",
"as_iterable",
"goos_to_extension",
"goos_to_shared_extension",
"is_struct",
)
load(
Expand Down Expand Up @@ -569,8 +567,6 @@ def go_context(ctx, attr = None):
sdk_root = toolchain.sdk.root_file,
sdk_tools = toolchain.sdk.tools,
actions = ctx.actions,
exe_extension = goos_to_extension(mode.goos),
shared_extension = goos_to_shared_extension(mode.goos),
cc_toolchain_files = cc_toolchain_files,
package_list = toolchain.sdk.package_list,
importpath = importpath,
Expand Down
10 changes: 0 additions & 10 deletions go/toolchains.rst
Original file line number Diff line number Diff line change
Expand Up @@ -591,16 +591,6 @@ Fields
| The actions structure from the Bazel context, which has all the methods for building new |
| bazel actions. |
+--------------------------------+-----------------------------------------------------------------+
| :param:`exe_extension` | :type:`string` |
+--------------------------------+-----------------------------------------------------------------+
| The suffix to use for all executables in this build mode. Mostly used when generating the output |
| filenames of binary rules. |
+--------------------------------+-----------------------------------------------------------------+
| :param:`shared_extension` | :type:`string` |
+--------------------------------+-----------------------------------------------------------------+
| The suffix to use for shared libraries in this build mode. Mostly used when |
| generating output filenames of binary rules. |
+--------------------------------+-----------------------------------------------------------------+
| :param:`cc_toolchain_files` | :type:`list of File` |
+--------------------------------+-----------------------------------------------------------------+
| The files you need to add to the inputs of an action in order to use the cc toolchain. |
Expand Down

0 comments on commit c419453

Please sign in to comment.