Skip to contentSkip to conversation

rust: add `rustcheck` make target for check-only builds

PATCH In review Onur Özkan 3 participants 7 messages Sep 15, 2025 – Oct 10, 2025

Subsystems (2)
lore
Share & tools
lore

Onur Özkan

author reviewer
#0 lore raw

v2 cover rust: add `rustcheck` make target for check-only builds

Changes in v2:
- Couple of indentation fixes in rust/Makefile.

Onur Özkan (1):
rust: add rustcheck make target for check-only builds

 Makefile      |  7 +++++
 rust/Makefile | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)
Signature · 1 line
2.51.0
author reviewer
#1 lore raw

PATCH v2 1/1 rust: add `rustcheck` make target for check-only builds

Adds a new rustcheck make target to run a check-only build similar to cargo check. This allows us to verify that the Rust sources can build without building/linking final artifacts, which speeds up the iteration (a lot) during development.

The target also supports the CLIPPY flag (e.g., `make LLVM=1 rustcheck CLIPPY=1) to run Clippy in a faster way.

Also, unlike make LLVM=1, it doesn't compile large amounts of C code (on a fresh checkout) when the goal is only to check that Rust builds are not broken after some changes.

---
 Makefile      |  7 +++++
 rust/Makefile | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)
Makefile +7 -0
index cf37b9407821..7812cdc72938 100644
@@ -1716,6 +1716,8 @@ help:
 	@echo  '		    is formatted, printing a diff otherwise.'
 	@echo  '  rustdoc	  - Generate Rust documentation'
 	@echo  '		    (requires kernel .config)'
+	@echo  '  rustcheck       - Check that the Rust code builds'
+	@echo  '                    (requires kernel .config)'
 	@echo  '  rusttest        - Runs the Rust tests'
 	@echo  '                    (requires kernel .config; downloads external repos)'
 	@echo  '  rust-analyzer	  - Generate rust-project.json rust-analyzer support file'
@@ -1821,6 +1823,11 @@ PHONY += rustdoc
 rustdoc: prepare
 	$(Q)$(MAKE) $(build)=rust $@
 
+# Checking Rust sources.
+PHONY += rustcheck
+rustcheck: prepare0
+	$(Q)$(MAKE) $(build)=rust $@
+
 # Testing target
 PHONY += rusttest
 rusttest: prepare
rust/Makefile +73 -0

79 lines not on this page · raw message

Signature · 1 line
2.51.0
#2 lore raw
Quoted 34 lines · Onur Özkan

Adds a new rustcheck make target to run a check-only build similar to cargo check. This allows us to verify that the Rust sources can build without building/linking final artifacts, which speeds up the iteration (a lot) during development.

The target also supports the CLIPPY flag (e.g., `make LLVM=1 rustcheck CLIPPY=1) to run Clippy in a faster way.

Also, unlike make LLVM=1, it doesn't compile large amounts of C code (on a fresh checkout) when the goal is only to check that Rust builds are not broken after some changes.

---
 Makefile      |  7 +++++
 rust/Makefile | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)
Makefile +2 -0
index cf37b9407821..7812cdc72938 100644
@@ -1716,6 +1716,8 @@ help:
 	@echo  '		    is formatted, printing a diff otherwise.'
 	@echo  '  rustdoc	  - Generate Rust documentation'
 	@echo  '		    (requires kernel .config)'
+	@echo  '  rustcheck       - Check that the Rust code builds'
+	@echo  '                    (requires kernel .config)'
 	@echo  '  rusttest        - Runs the Rust tests'
 	@echo  '                    (requires kernel .config; downloads external repos)'
 	@echo  '  rust-analyzer	  - Generate rust-project.json rust-analyzer support file'

Makefile PHONY += rustdoc · line 1828

Quoted 6 lines
Makefile +3 -0
@@ -1821,6 +1823,11 @@ PHONY += rustdoc
 rustdoc: prepare
 	$(Q)$(MAKE) $(build)=rust $@
 
+# Checking Rust sources.
+PHONY += rustcheck
+rustcheck: prepare0

Why do you let rustcheck depend on prepare0 instead of prepare?

Quoted 10 lines
Makefile +2 -0
+	$(Q)$(MAKE) $(build)=rust $@
+
 # Testing target
 PHONY += rusttest
 rusttest: prepare
rust/Makefile +0 -0
index bfa915b0e588..b45878870207 100644

rust/Makefile rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-ffi rusttestlib-kernel \ · line 271

Quoted 7 lines
rust/Makefile +4 -0
@@ -265,6 +265,79 @@ rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-ffi rusttestlib-kernel \
     rusttestlib-uapi rusttestlib-pin_init FORCE
 	+$(call if_changed,rustc_test)
 
+## Check-only compilation (similar to `cargo check`)
+quiet_cmd_rustc_check_library = $(RUSTC_OR_CLIPPY_QUIET) CHECK $<
+      cmd_rustc_check_library = \
+        OBJTREE=$(abspath $(objtree)) \

Have you tried this?

        OBJTREE=$(CURDIR) \

or

        OBJTREE=$(abs_output) \

I'd favor using one of these instead.

Kind regards,
Nicolas

author reviewer
#3 lore raw
Quoted 41 lines · On Mon, 22 Sep 2025 08:02:36 +0200 Nicolas Schier <[email protected]>…
Quoted 40 lines · Onur Özkan

Adds a new rustcheck make target to run a check-only build similar to cargo check. This allows us to verify that the Rust sources can build without building/linking final artifacts, which speeds up the iteration (a lot) during development.

The target also supports the CLIPPY flag (e.g., `make LLVM=1 rustcheck CLIPPY=1) to run Clippy in a faster way.

Also, unlike make LLVM=1, it doesn't compile large amounts of C code (on a fresh checkout) when the goal is only to check that Rust builds are not broken after some changes.

Link:
https://rust-for-linux.zulipchat.com/#narrow/channel/288089/topic/x/near/539103602

 Makefile      |  7 +++++
 rust/Makefile | 73

+++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+)

Makefile +0 -0
index cf37b9407821..7812cdc72938 100644
@@ -1716,6 +1716,8 @@ help:
 	@echo  '		    is formatted, printing a diff

otherwise.' @echo ' rustdoc - Generate Rust
documentation' @echo ' (requires kernel
.config)'

Makefile +1 -0
+	@echo  '  rustcheck       - Check that the Rust code

builds'

Makefile +1 -0
+	@echo  '                    (requires kernel .config)'
 	@echo  '  rusttest        - Runs the Rust tests'
 	@echo  '                    (requires kernel .config;

downloads external repos)' @echo ' rust-analyzer -
Generate rust-project.json rust-analyzer support file' @@ -1821,6 +1823,11 @@ PHONY += rustdoc rustdoc: prepare
$(Q)$(MAKE) $(build)=rust $@

Quoted 6 lines

Makefile PHONY += rustdoc · line 1828

Quoted 3 lines
Makefile +3 -0
+# Checking Rust sources.
+PHONY += rustcheck
+rustcheck: prepare0

Why do you let rustcheck depend on prepare0 instead of prepare?

Because "prepare" does more job which isn't necessary (therefore waste of time) for "rustcheck".

Quoted 20 lines
Quoted 13 lines
Makefile +2 -0
+	$(Q)$(MAKE) $(build)=rust $@
+
 # Testing target
 PHONY += rusttest
 rusttest: prepare
rust/Makefile +0 -0
index bfa915b0e588..b45878870207 100644
@@ -265,6 +265,79 @@ rusttest-kernel: $(src)/kernel/lib.rs

rusttestlib-ffi rusttestlib-kernel \ rusttestlib-uapi rusttestlib-pin_init FORCE +$(call if_changed,rustc_test)

rust/Makefile rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-ffi rusttestlib-kernel \ · line 271

Quoted 4 lines
rust/Makefile +4 -0
+## Check-only compilation (similar to `cargo check`)
+quiet_cmd_rustc_check_library = $(RUSTC_OR_CLIPPY_QUIET) CHECK $<
+      cmd_rustc_check_library = \
+        OBJTREE=$(abspath $(objtree)) \

Have you tried this?

Quoted 8 lines
        OBJTREE=$(CURDIR) \

or

        OBJTREE=$(abs_output) \

I'd favor using one of these instead.

I don't have a strong opinion on any of them. I followed the existing approach from the other use cases used in the same file.

Regards,
Onur

maintainer Acked-by
#4 lore raw
Quoted 78 lines · Onur Özkan
Quoted 41 lines · On Mon, 22 Sep 2025 08:02:36 +0200 Nicolas Schier <[email protected]>…
Quoted 40 lines · Onur Özkan

Adds a new rustcheck make target to run a check-only build similar to cargo check. This allows us to verify that the Rust sources can build without building/linking final artifacts, which speeds up the iteration (a lot) during development.

The target also supports the CLIPPY flag (e.g., `make LLVM=1 rustcheck CLIPPY=1) to run Clippy in a faster way.

Also, unlike make LLVM=1, it doesn't compile large amounts of C code (on a fresh checkout) when the goal is only to check that Rust builds are not broken after some changes.

Link:
https://rust-for-linux.zulipchat.com/#narrow/channel/288089/topic/x/near/539103602

 Makefile      |  7 +++++
 rust/Makefile | 73

+++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+)

Makefile +0 -0
index cf37b9407821..7812cdc72938 100644
@@ -1716,6 +1716,8 @@ help:
 	@echo  '		    is formatted, printing a diff

otherwise.' @echo ' rustdoc - Generate Rust
documentation' @echo ' (requires kernel
.config)'

Makefile +1 -0
+	@echo  '  rustcheck       - Check that the Rust code

builds'

Makefile +1 -0
+	@echo  '                    (requires kernel .config)'
 	@echo  '  rusttest        - Runs the Rust tests'
 	@echo  '                    (requires kernel .config;

downloads external repos)' @echo ' rust-analyzer -
Generate rust-project.json rust-analyzer support file' @@ -1821,6 +1823,11 @@ PHONY += rustdoc rustdoc: prepare
$(Q)$(MAKE) $(build)=rust $@

Quoted 6 lines

Makefile PHONY += rustdoc · line 1828

Quoted 3 lines
Makefile +3 -0
+# Checking Rust sources.
+PHONY += rustcheck
+rustcheck: prepare0

Why do you let rustcheck depend on prepare0 instead of prepare?

Because "prepare" does more job which isn't necessary (therefore waste of time) for "rustcheck".

Quoted 24 lines
Quoted 13 lines
Makefile +2 -0
+	$(Q)$(MAKE) $(build)=rust $@
+
 # Testing target
 PHONY += rusttest
 rusttest: prepare
rust/Makefile +0 -0
index bfa915b0e588..b45878870207 100644
@@ -265,6 +265,79 @@ rusttest-kernel: $(src)/kernel/lib.rs

rusttestlib-ffi rusttestlib-kernel \ rusttestlib-uapi rusttestlib-pin_init FORCE +$(call if_changed,rustc_test)

rust/Makefile rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-ffi rusttestlib-kernel \ · line 271

Quoted 4 lines
rust/Makefile +4 -0
+## Check-only compilation (similar to `cargo check`)
+quiet_cmd_rustc_check_library = $(RUSTC_OR_CLIPPY_QUIET) CHECK $<
+      cmd_rustc_check_library = \
+        OBJTREE=$(abspath $(objtree)) \

Have you tried this?

        OBJTREE=$(CURDIR) \

or

Quoted 7 lines
Quoted 4 lines
        OBJTREE=$(abs_output) \

I'd favor using one of these instead.

I don't have a strong opinion on any of them. I followed the existing approach from the other use cases used in the same file.

well, you're right, it's not really consistent right now.

author reviewer
#5 lore raw
In reply to Onur Özkan
Quoted 11 lines · On Mon, 15 Sep 2025 14:53:10 +0300 Onur Özkan <[email protected]> wrote:

Changes in v2:
- Couple of indentation fixes in rust/Makefile.

Onur Özkan (1):
rust: add rustcheck make target for check-only builds

 Makefile      |  7 +++++
 rust/Makefile | 73

+++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+)

Should we document this target on [0]? I think it will be used quite frequently by Rust developers on the kernel once we land it, so I think it's worth documenting. I can include a patch for that if others would agree.

[0]: https://docs.kernel.org/rust/quick-start.html

Regards,
Onur

author reviewer
#6 lore raw
In reply to Onur Özkan
Quoted 11 lines · On Mon, 15 Sep 2025 14:53:10 +0300 Onur Özkan <[email protected]> wrote:

Changes in v2:
- Couple of indentation fixes in rust/Makefile.

Onur Özkan (1):
rust: add rustcheck make target for check-only builds

 Makefile      |  7 +++++
 rust/Makefile | 73

+++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+)

A friendly ping on this patch. It's been over two weeks with no feedback, would appreciate any thoughts or suggestions.

Regards,
Onur