Build Linux and the Linux driver out of tree
Linux and the Hafnium module have been built inside their source tree so
far. The targets have a hardcoded toolchain but they get built multiple
times, once for each toolchain defined in GN. This can cause the build
to fail when two instances attempt to compile the same file at the same
time. Refactor the build scripts to compile the kernel and the module
in the out/ directory of each corresponding toolchain.
This cleans up the build files a bit but also introduces a new problem.
Out-of-tree kernel modules do not support building out of their folder.
This patch avoids that by copying the source files into
`target_out_dir`.
Test: kokoro/ubuntu/build.sh
Change-Id: I6fc10ebd9623f5f82dd086447b80d935c490765e
diff --git a/driver/BUILD.gn b/driver/BUILD.gn
index f6f4119..0fae976 100644
--- a/driver/BUILD.gn
+++ b/driver/BUILD.gn
@@ -12,28 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-action("linux") {
- script = "//build/make.py"
- args = [
- "--directory",
- rebase_path("linux"),
- "--out_file",
- "hafnium.ko",
- "--copy_out_file",
- rebase_path("${target_out_dir}/linux/hafnium.ko"),
- "CC=" + rebase_path("//prebuilts/linux-x64/clang/bin/clang"),
- "ARCH=arm64",
- "CROSS_COMPILE=aarch64-linux-gnu-",
- ]
+import("//build/linux/linux.gni")
+
+linux_kernel_module("linux") {
+ module_name = "hafnium"
+ kernel_target = "//third_party:linux"
+ kernel_src_dir = "//third_party/linux"
sources = [
"linux/Makefile",
"linux/hf_call.S",
"linux/main.c",
]
- outputs = [
- "${target_out_dir}/linux/hafnium.ko",
- ]
- deps = [
- "//third_party:linux_defconfig",
- ]
}