diff --git a/build_defs/cgo.build_defs b/build_defs/cgo.build_defs index 0193a32..0fb2809 100644 --- a/build_defs/cgo.build_defs +++ b/build_defs/cgo.build_defs @@ -89,10 +89,14 @@ 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'], @@ -100,14 +104,12 @@ 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" -- {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 = [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,