Skip to content

Commit 533bdbe

Browse files
committed
[rust] Clean up HAVE/USE RUST configuration
Cleanly separate enablement of Rust support from a `USE_RUST` that can be used when invoking make, and `HAVE_RUST` that is defined internally when rust support is enabled. This allows targets to decide for themselves if Rust support is needed, or if it is optional. The definitive decision about rust support will be determined if a platform makefile includes `lib/rust_support/rules.mk` to include Rust support in the build. It can optional do this based on a use-defined `USE_RUST` flag. Signed-off-by: David Brown <[email protected]>
1 parent 2d268af commit 533bdbe

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

dev/uart/pl011/uart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "dev/uart/pl011.h"
99

1010
/* If rust is in use, use the Rust implementation of this driver. */
11-
#if !USE_RUST
11+
#if !HAVE_RUST
1212

1313
#include <assert.h>
1414
#include <dev/uart.h>
@@ -231,4 +231,4 @@ void uart_flush_rx(int port) {
231231
void uart_init_port(int port, uint baud) {
232232
}
233233

234-
#endif /* not USE_RUST */
234+
#endif /* not HAVE_RUST */

lib/rust_support/rules.mk

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ MODULE_SRCS := \
2525
$(MODULE_SRCDIR)/src/lib.rs
2626
MODULE_OBJS := $(foreach d,$(MODULE_SRCS),$(call TOBUILDDIR,$(d)))
2727

28-
# The platform must set RUST_TARGET and RUST_TARGET_PATH. If RUST_TARGET is a
29-
# standard tuple, RUST_TARGET_PATH should have the same value. Otherwise,
30-
# RUST_TARGET_PATH should point to the custom target json file, and RUST_TARGET
31-
# should be the basename of the json file.
28+
# USE_RUST can be used by platforms to allow invocation to determine if rust
29+
# support is present. However, when this module is included, we have rust
30+
# support. The define `HAVE_RUST` will indicate that rust is actually being
31+
# used.
32+
HAVE_RUST := 1
33+
34+
GLOBAL_DEFINES += HAVE_RUST=$(HAVE_RUST)
3235

3336
ifeq ($(RUST_TARGET),)
3437
$(error RUST_TARGET is not set for rust support)

platform/qemu-virt-arm/platform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void platform_early_init(void) {
8787
fdtwalk_setup_memory(fdt, MEMORY_BASE_PHYS, MEMORY_BASE_PHYS, DEFAULT_MEMORY_SIZE);
8888
}
8989

90-
#if USE_RUST
90+
#if HAVE_RUST
9191
void setup_rust(void);
9292
#else
9393
static void setup_rust(void) {}

platform/qemu-virt-arm/rules.mk

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ MEMBASE := 0x40000000
2424
MEMSIZE ?= 0x08000000 # 512MB
2525
KERNEL_LOAD_OFFSET := 0x100000 # 1MB
2626

27-
USE_RUST ?= 0
28-
2927
MODULE_DEPS += \
3028
dev/bus/pci \
3129
dev/bus/pci/drivers \
@@ -41,6 +39,8 @@ MODULE_DEPS += \
4139
lib/fdtwalk \
4240
lib/fs/9p \
4341

42+
USE_RUST ?= 0
43+
4444
ifeq ($(USE_RUST),1)
4545
MODULE_DEPS += lib/rust_support
4646
endif
@@ -50,8 +50,7 @@ GLOBAL_DEFINES += \
5050
MEMSIZE=$(MEMSIZE) \
5151
PLATFORM_SUPPORTS_PANIC_SHELL=1 \
5252
CONSOLE_HAS_INPUT_BUFFER=1 \
53-
TIMER_ARM_GENERIC_SELECTED=CNTV \
54-
USE_RUST=$(USE_RUST)
53+
TIMER_ARM_GENERIC_SELECTED=CNTV
5554

5655
GLOBAL_DEFINES += MMU_WITH_TRAMPOLINE=1
5756

0 commit comments

Comments
 (0)