Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions build_defs/cgo.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,27 @@ 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([
(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,
Expand Down