Skip to content

Commit

Permalink
GoSource can store dependent archives instead of full deps
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbarsky committed Aug 13, 2024
1 parent 517a1f9 commit 4b07810
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
3 changes: 1 addition & 2 deletions go/private/actions/archive.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ load(
"GoArchive",
"GoArchiveData",
"effective_importpath_pkgpath",
"get_archive",
)
load(
"//go/private/actions:compilepkg.bzl",
Expand Down Expand Up @@ -74,7 +73,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
out_nogo_log = None
out_nogo_validation = None

direct = [get_archive(dep) for dep in source.deps]
direct = source.deps

files = []
for a in direct:
Expand Down
4 changes: 4 additions & 0 deletions go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ load(
"GoSource",
"GoStdLib",
"INFERRED_PATH",
"get_archive",
"get_source",
)

Expand Down Expand Up @@ -316,6 +317,9 @@ def _library_to_source(go, attr, library, coverage_instrumented):
if library.resolve:
library.resolve(go, attr, source, _merge_embed)
source["cc_info"] = _collect_cc_infos(source["deps"], source["cdeps"])

source["deps"] = [get_archive(dep) for dep in source["deps"]]

return GoSource(**source)

def _collect_runfiles(go, data, deps):
Expand Down
13 changes: 6 additions & 7 deletions go/private/rules/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ load(
"GoLibrary",
"GoSource",
"INFERRED_PATH",
"get_archive",
)
load(
"//go/private/rules:binary.bzl",
Expand Down Expand Up @@ -525,7 +524,7 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe
# Build a map from labels to GoArchiveData.
# If none of the librares embedded in the internal archive are in the
# dependency graph, then nothing needs to be recompiled.
arc_data_list = depset(transitive = [get_archive(dep).transitive for dep in external_source.deps]).to_list()
arc_data_list = depset(transitive = [archive.transitive for archive in external_source.deps]).to_list()
label_to_arc_data = {a.label: a for a in arc_data_list}
if all([l not in label_to_arc_data for l in library_labels]):
return external_source, internal_archive
Expand All @@ -543,7 +542,7 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe
dep_list = []

# stack is a stack of targets to process. We're done when it's empty.
stack = [get_archive(dep).data.label for dep in external_source.deps]
stack = [archive.data.label for archive in external_source.deps]

# deps_pushed tracks the status of each target.
# DEPS_UNPROCESSED means the target is on the stack, but its dependencies
Expand Down Expand Up @@ -622,10 +621,10 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe
# Pass internal dependencies that need to be recompiled down to the builder to check if the internal archive
# tries to import any of the dependencies. If there is, that means that there is a dependency cycle.
need_recompile_deps = []
for dep in internal_source.deps:
dep_data = get_archive(dep).data
for archive in internal_source.deps:
dep_data = archive.data
if not need_recompile[dep_data.label]:
internal_deps.append(dep)
internal_deps.append(archive)
else:
need_recompile_deps.append(dep_data.importpath)

Expand Down Expand Up @@ -712,5 +711,5 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe
# Finally, we need to replace external_source.deps with the recompiled
# archives.
attrs = structs.to_dict(external_source)
attrs["deps"] = [label_to_archive[get_archive(dep).data.label] for dep in external_source.deps]
attrs["deps"] = [label_to_archive[archive.data.label] for archive in external_source.deps]
return GoSource(**attrs), internal_archive
2 changes: 1 addition & 1 deletion go/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ method. In general, only rules_go should need to build or handle these.
+--------------------------------+-----------------------------------------------------------------+
| Map of defines to add to the go link command. |
+--------------------------------+-----------------------------------------------------------------+
| :param:`deps` | :type:`list of Target` |
| :param:`deps` | :type:`list of GoArchive` |
+--------------------------------+-----------------------------------------------------------------+
| The direct dependencies needed by this library. |
+--------------------------------+-----------------------------------------------------------------+
Expand Down

0 comments on commit 4b07810

Please sign in to comment.