I'm attempting to build a number of out-of-tree linux kernel modules with bazel. We currently have a build process set up with scons wrapping the standard linux kernel Makefile/Kbuild process as documented here:
My goal is to have the bazel cc_toolchain and all of its properties like default flags, etc,. be used to compile the source code. I would appreciate any guidance for this.
The naïve approach I elected to take was to use the rules_foreign_cc make command to wrap the compilation. However, this caused the sandboxing code itself to fail in the clone() call:
INFO: Analyzed 2 targets (1 packages loaded, 6 targets configured).
INFO: Found 2 targets...
ERROR: /var/tmp/gk/bazel_cache/ef3bbf913ac361d05440a740f3caf795/external/rules_foreign_cc/toolchains/BUILD.bazel:71:10: BootstrapGNUMake external/rules_foreign_cc/toolchains/make [for host] failed: (Exit 1): linux-sandbox failed: error executing command
(cd /var/tmp/gk/bazel_cache/ef3bbf913ac361d05440a740f3caf795/sandbox/linux-sandbox/7/execroot/__main__ && \
exec env - \
PATH=/home/garrettkajmowicz/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/storage/build_tools \
TMPDIR=/tmp \
/var/tmp/gk/bazel_cache/install/f95ca91ebc34d56aa0f8ad499de91220/linux-sandbox -t 15 -w /var/tmp/gk/bazel_cache/ef3bbf913ac361d05440a740f3caf795/sandbox/linux-sandbox/7/execroot/__main__ -w /tmp -w /dev/shm -N -D -- /bin/bash -c bazel-out/host/bin/external/rules_foreign_cc/toolchains/make_tool_foreign_cc/wrapper_build_script.sh)
1624469169.911993005: src/main/tools/linux-sandbox.cc:152: calling pipe(2)...
1624469169.912087730: src/main/tools/linux-sandbox.cc:171: calling clone(2)...
src/main/tools/linux-sandbox.cc:177: "clone": File exists
INFO: Elapsed time: 12.153s, Critical Path: 0.12s
INFO: 3 processes: 3 internal.
FAILED: Build did NOT complete successfully
The BUILD file I'm using is:
load("@rules_foreign_cc//foreign_cc:defs.bzl", "make")
filegroup(
name="nfnetmap_queue_src",
srcs = [
"nfnetmap_queue.c",
"nfnetmap_queue_meta.h",
"Kbuild",
"Makefile",
],
)
make(
name = "nfnetmap_queue",
data = ["@kernel_source_host//:whole_kernel_tree"],
lib_source = ":nfnetmap_queue_src",
out_binaries = ["nfnetmap_queue.ko"],
)
Currently using bazel 4.1.0 and rules_foreign_cc at commit 78dd4749941 from Jan 31, 2021.
- Garrett