Skip to content

Commit

Permalink
Support -complete flag to Go compiler
Browse files Browse the repository at this point in the history
Summary:
From the task:
> We miss flag -complete that the standard build-system adds when there are not other files besides of plain Go.
It doesn't do any significant job for now just ensures some safety, but it's good to follow the reference build-system implementation.

Reviewed By: podtserkovskiy

Differential Revision: D68097048

fbshipit-source-id: 19b57465a01e654135ea6d788b48ee68d8865b54
  • Loading branch information
inesusvet authored and facebook-github-bot committed Jan 14, 2025
1 parent 8e81a3b commit ffa00ca
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion prelude/go/package_builder.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,30 @@ def build_package(

symabis = _symabis(ctx, pkg_name, main, go_list.s_files, go_list.h_files, assembler_flags)

# Use -complete flag when compiling Go code only
complete_flag = len(go_list.cgo_files) + len(go_list.s_files) == 0

def build_variant(shared: bool) -> Artifact:
suffix = ",shared" if shared else ",non-shared" # suffix to make artifacts unique
go_files_to_compile = covered_go_files + ((go_list.test_go_files + go_list.x_test_go_files) if tests else [])
importcfg = make_importcfg(ctx, pkg_name, all_pkgs, shared)
go_a_file, asmhdr = _compile(ctx, pkg_name, main, go_files_to_compile, importcfg, compiler_flags, shared, race, asan, suffix, embedcfg, go_list.embed_files, symabis, len(go_list.s_files) > 0)
go_a_file, asmhdr = _compile(
ctx = ctx,
pkg_name = pkg_name,
main = main,
go_srcs = go_files_to_compile,
importcfg = importcfg,
compiler_flags = compiler_flags,
shared = shared,
race = race,
asan = asan,
suffix = suffix,
complete = complete_flag,
embedcfg = embedcfg,
embed_files = go_list.embed_files,
symabis = symabis,
gen_asmhdr = len(go_list.s_files) > 0,
)

asm_o_files = _asssembly(ctx, pkg_name, main, go_list.s_files, go_list.h_files, asmhdr, assembler_flags, shared, suffix)

Expand Down Expand Up @@ -113,6 +132,7 @@ def _compile(
race: bool,
asan: bool,
suffix: str,
complete: bool,
embedcfg: Artifact | None = None,
embed_files: list[Artifact] = [],
symabis: Artifact | None = None,
Expand Down Expand Up @@ -150,6 +170,7 @@ def _compile(
["-embedcfg", embedcfg] if embedcfg else [],
["-symabis", symabis] if symabis else [],
["-asmhdr", asmhdr.as_output()] if asmhdr else [],
["-complete"] if complete else [],
cmd_args(srcs_argsfile, format = "@{}", hidden = go_srcs),
],
hidden = embed_files, # files and directories should be available for embedding
Expand Down

0 comments on commit ffa00ca

Please sign in to comment.