From 6a9f97b176ad570510c9444a59ed0934f4b6d938 Mon Sep 17 00:00:00 2001 From: jackmarsh Date: Tue, 23 Dec 2025 15:50:35 +0000 Subject: [PATCH 1/3] fix(cgo): Use named tools syntax for RBE compatibility The cgo_library rule was using unnamed tools syntax (tools = [CONFIG.GO.GO_TOOL]) with $TOOL variable. This causes remote build execution to fail because Please doesn't include tool outputs in the remote action's input tree when using this syntax. This change switches to named tools syntax (tools = {"go": CONFIG.GO.GO_TOOL}) with $TOOLS_GO variable, which is consistent with how _go_library_cmds handles tools and enables proper RBE support for cgo builds. --- build_defs/cgo.build_defs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_defs/cgo.build_defs b/build_defs/cgo.build_defs index 0193a32b..e84609a8 100644 --- a/build_defs/cgo.build_defs +++ b/build_defs/cgo.build_defs @@ -101,13 +101,13 @@ def cgo_library( cmd = ' && '.join([ (f'OUT_DIR="$TMP_DIR/{subdir}" && mkdir -p "$OUT_DIR"') if subdir else 'OUT_DIR="$TMP_DIR"', 'cd $PKG_DIR/' + subdir, - f'$TOOL tool cgo -objdir "$OUT_DIR" -importpath {import_path} -trimpath "$TMP_DIR" -- {compiler_flags_cmd} *.go', + f'$TOOLS_GO tool cgo -objdir "$OUT_DIR" -importpath {import_path} -trimpath "$TMP_DIR" -- {compiler_flags_cmd} *.go', # Remove the .o file which BSD sed gets upset about in the next command 'rm -f "$OUT_DIR"/_cgo_.o "$OUT_DIR"/_cgo_main.c', 'cd "$TMP_DIR"', f'ls {subdir2}*.c {subdir2}*.go', ]), - tools = [CONFIG.GO.GO_TOOL], + tools = {"go": CONFIG.GO.GO_TOOL}, post_build = post_build if file_srcs != srcs else None, requires = ['go', 'go_src', 'cc_hdrs', 'hdrs'], deps = deps, From d31fe4bef41efe735e777b9674daf047a8b45422 Mon Sep 17 00:00:00 2001 From: jackmarsh Date: Tue, 23 Dec 2025 16:37:54 +0000 Subject: [PATCH 2/3] fix(cgo): Make tool path absolute before cd for remote execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cgo_library rule changes directory with 'cd $PKG_DIR/' before running the go tool. This is necessary because: 1. The *.go glob needs the correct working directory 2. Header files must be relative to cgo's working directory for #include In remote execution, tool paths are relative to $TMP_DIR. After the cd, these relative paths become invalid. Fix: Convert tool path to absolute before the cd using a case statement. Uses $TMP_DIR/$TOOLS_GO for relative paths (remote), keeps absolute paths unchanged (local). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- build_defs/cgo.build_defs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build_defs/cgo.build_defs b/build_defs/cgo.build_defs index e84609a8..e9630c85 100644 --- a/build_defs/cgo.build_defs +++ b/build_defs/cgo.build_defs @@ -99,9 +99,11 @@ def cgo_library( 'h': [subdir2 + '_cgo_export.h'], }, cmd = ' && '.join([ + # Make tool path absolute before cd since tools may be relative to $TMP_DIR in remote execution + 'case "$TOOLS_GO" in /*) GO_TOOL="$TOOLS_GO";; *) GO_TOOL="$TMP_DIR/$TOOLS_GO";; esac', (f'OUT_DIR="$TMP_DIR/{subdir}" && mkdir -p "$OUT_DIR"') if subdir else 'OUT_DIR="$TMP_DIR"', 'cd $PKG_DIR/' + subdir, - f'$TOOLS_GO tool cgo -objdir "$OUT_DIR" -importpath {import_path} -trimpath "$TMP_DIR" -- {compiler_flags_cmd} *.go', + f'"$GO_TOOL" tool cgo -objdir "$OUT_DIR" -importpath {import_path} -trimpath "$TMP_DIR" -- {compiler_flags_cmd} *.go', # Remove the .o file which BSD sed gets upset about in the next command 'rm -f "$OUT_DIR"/_cgo_.o "$OUT_DIR"/_cgo_main.c', 'cd "$TMP_DIR"', From 5cd196cb3fd2eccb99719c63494b35b05718124e Mon Sep 17 00:00:00 2001 From: jackmarsh Date: Tue, 23 Dec 2025 16:56:08 +0000 Subject: [PATCH 3/3] fix(cgo): support remote execution The cd $PKG_DIR pattern breaks when tool paths are relative, which happens in remote execution. This removes the cd and instead uses named srcs with $SRCS_GO directly, adding -I$PKG_DIR for headers. --- build_defs/cgo.build_defs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build_defs/cgo.build_defs b/build_defs/cgo.build_defs index e9630c85..0fb28090 100644 --- a/build_defs/cgo.build_defs +++ b/build_defs/cgo.build_defs @@ -89,24 +89,24 @@ def cgo_library( if pkg_config: pkg_configs = " ".join(pkg_config) compiler_flags_cmd = f"{compiler_flags_cmd} $(pkg-config --cflags {pkg_configs})" + include_flag = f'-I$PKG_DIR/{subdir}' if subdir else '-I$PKG_DIR' cgo_rule = build_rule( name = name, tag = 'cgo', - srcs = srcs + hdrs, + srcs = { + 'go': srcs, + 'h': hdrs, + }, outs = { 'go': [subdir2 + src.replace('.go', '.cgo1.go') for src in file_srcs] + [subdir2 + '_cgo_gotypes.go'], 'c': [subdir2 + src.replace('.go', '.cgo2.c') for src in file_srcs] + [subdir2 + '_cgo_export.c'], 'h': [subdir2 + '_cgo_export.h'], }, cmd = ' && '.join([ - # Make tool path absolute before cd since tools may be relative to $TMP_DIR in remote execution - 'case "$TOOLS_GO" in /*) GO_TOOL="$TOOLS_GO";; *) GO_TOOL="$TMP_DIR/$TOOLS_GO";; esac', (f'OUT_DIR="$TMP_DIR/{subdir}" && mkdir -p "$OUT_DIR"') if subdir else 'OUT_DIR="$TMP_DIR"', - 'cd $PKG_DIR/' + subdir, - f'"$GO_TOOL" tool cgo -objdir "$OUT_DIR" -importpath {import_path} -trimpath "$TMP_DIR" -- {compiler_flags_cmd} *.go', + f'$TOOLS_GO tool cgo -objdir "$OUT_DIR" -importpath {import_path} -trimpath "$TMP_DIR" -- {include_flag} {compiler_flags_cmd} $SRCS_GO', # Remove the .o file which BSD sed gets upset about in the next command 'rm -f "$OUT_DIR"/_cgo_.o "$OUT_DIR"/_cgo_main.c', - 'cd "$TMP_DIR"', f'ls {subdir2}*.c {subdir2}*.go', ]), tools = {"go": CONFIG.GO.GO_TOOL},