Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit 7394cf0

Browse files
committed
Go back to using KDIR to find the kernel sources (fixes #243)
On Debian, abs_srctree points to /usr/share/linux-headers-x.y-common, which doesn't have generated arch-specific headers. We previously ran into a similar problem in kernel-cflags-finder regarding expanding includes in the right directory (see the comment in b637890). abs_objtree seems to work but I'm not sure that's reliable, it sounds like it's usable for out-of-tree builds in some fashion. CURDIR would work, but since we're using KDIR in the parent Makefile which does a `make -C $(KDIR)`, we may as well export and use that variable.
1 parent 51688f9 commit 7394cf0

File tree

5 files changed

+4
-6
lines changed

5 files changed

+4
-6
lines changed

build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ fn prepare_cflags(cflags: &str, kernel_dir: &str) -> Vec<String> {
137137

138138
fn main() {
139139
println!("cargo:rerun-if-env-changed=CC");
140-
println!("cargo:rerun-if-env-changed=abs_srctree");
140+
println!("cargo:rerun-if-env-changed=KDIR");
141141
println!("cargo:rerun-if-env-changed=c_flags");
142142

143-
let kernel_dir = env::var("abs_srctree").expect("Must be invoked from kernel makefile");
143+
let kernel_dir = env::var("KDIR").expect("Must be invoked from kernel makefile");
144144
let kernel_cflags = env::var("c_flags").expect("Add 'export c_flags' to Kbuild");
145145

146146
let kernel_args = prepare_cflags(&kernel_cflags, &kernel_dir);

hello-world/Kbuild

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ helloworld-objs := hello_world.rust.o
44
CARGO ?= cargo
55

66
export c_flags
7-
export abs_srctree ?= ${CURDIR}
87

98
$(src)/target/x86_64-linux-kernel/debug/libhello_world.a: $(src)/Cargo.toml $(wildcard $(src)/src/*.rs)
109
cd $(src); $(CARGO) build -Z build-std=core,alloc --target=x86_64-linux-kernel

hello-world/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KDIR ?= /lib/modules/$(shell uname -r)/build
1+
export KDIR ?= /lib/modules/$(shell uname -r)/build
22

33
CLANG ?= clang
44
ifeq ($(origin CC),default)

tests/Kbuild

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ testmodule-objs := $(TEST_NAME).rust.o
44
CARGO ?= cargo
55

66
export c_flags
7-
export abs_srctree ?= ${CURDIR}
87

98
$(src)/target/x86_64-linux-kernel/debug/lib%.a: $(src)/$(TEST_PATH)/Cargo.toml $(wildcard $(src)/$(TEST_PATH)/src/*.rs)
109
cd $(src)/$(TEST_PATH); CARGO_TARGET_DIR=../target $(CARGO) build -Z build-std=core,alloc --target=x86_64-linux-kernel

tests/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KDIR ?= /lib/modules/$(shell uname -r)/build
1+
export KDIR ?= /lib/modules/$(shell uname -r)/build
22

33
CLANG ?= clang
44
ifeq ($(origin CC),default)

0 commit comments

Comments
 (0)