Skip to content

Commit e011fe6

Browse files
committed
[rust] a few intertwined rust build details
-Separate the two pl011 drivers so they do not need to be aware of each other: - make sure the platform selects the right one - have the rust one make a copy of the header for C code to interact with - Make the top level rust modules (app/rust_hello, rust/dev-pl011) use the LK module.mk which can now deal with empty modules. This cleans up the deps a little bit and uses existing machinery to add include paths. - Move the logic to select rust modules into the qemu-virt-arm64 project and have it conditionally include a new virtual project file that encapsulates rust deps. Will need to refacto this a bit later as more platform/projects make use of rust, but at least moves it up to the project level instead of down in a single platform.
1 parent 1d4af64 commit e011fe6

File tree

9 files changed

+57
-16
lines changed

9 files changed

+57
-16
lines changed

app/rust_hello/rules.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ $(info "Adding rust crate $(LOCAL_DIR)")
55

66
MODULE := $(LOCAL_DIR)
77

8-
MODULES += $(MODULE)
8+
MODULE_DEPS := lib/rust_support
99

10-
MODULE :=
10+
include make/module.mk

dev/uart/pl011/include/dev/uart/pl011.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
#pragma once
99

10-
#include <dev/uart.h>
1110
#include <stdint.h>
1211

1312
// Set this flag if the UART is a debug UART, which routes input

dev/uart/pl011/uart.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
*/
88
#include "dev/uart/pl011.h"
99

10-
/* If rust is in use, use the Rust implementation of this driver. */
11-
#if !HAVE_RUST
12-
1310
#include <assert.h>
1411
#include <dev/uart.h>
1512
#include <kernel/thread.h>
@@ -230,5 +227,3 @@ void uart_flush_rx(int port) {
230227
// TODO collapse this into the early/regular init routines
231228
void uart_init_port(int port, uint baud) {
232229
}
233-
234-
#endif /* not HAVE_RUST */

platform/qemu-virt-arm/platform.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <dev/interrupt/arm_gic.h>
1616
#include <dev/power/psci.h>
1717
#include <dev/timer/arm_generic.h>
18-
#include <dev/uart/pl011.h>
1918
#include <dev/virtio.h>
2019
#include <dev/virtio/net.h>
2120
#include <lib/fdtwalk.h>
@@ -29,6 +28,12 @@
2928
#if WITH_LIB_MINIP
3029
#include <lib/minip.h>
3130
#endif
31+
#if WITH_DEV_UART_PL011
32+
#include <dev/uart/pl011.h>
33+
#endif
34+
#if WITH_RUST_DEV_PL011
35+
#include <rust/dev-pl011.h>
36+
#endif
3237

3338
#define LOCAL_TRACE 0
3439

platform/qemu-virt-arm/rules.mk

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ MODULE_DEPS += \
3030
dev/interrupt/arm_gic \
3131
dev/power/psci \
3232
dev/timer/arm_generic \
33-
dev/uart/pl011 \
3433
dev/virtio/9p \
3534
dev/virtio/block \
3635
dev/virtio/gpu \
@@ -39,11 +38,11 @@ MODULE_DEPS += \
3938
lib/fdtwalk \
4039
lib/fs/9p \
4140

42-
USE_RUST ?= 0
43-
44-
ifeq ($(USE_RUST),1)
41+
ifeq ($(call TOBOOL,$(USE_RUST)),true)
4542
MODULE_DEPS += lib/rust_support
4643
MODULE_DEPS += rust/dev-pl011
44+
else
45+
MODULE_DEPS += dev/uart/pl011
4746
endif
4847

4948
GLOBAL_DEFINES += \

project/qemu-virt-arm64-test.mk

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# main project for qemu-aarch64
22
MODULES += \
33
app/shell \
4-
app/rust_hello \
5-
lib/uefi \
4+
lib/uefi
65

76
include project/virtual/test.mk
87
include project/virtual/fs.mk
98
include project/virtual/minip.mk
109
include project/target/qemu-virt-arm64.mk
10+
11+
USE_RUST ?= 0
12+
13+
ifeq ($(call TOBOOL,$(USE_RUST)),true)
14+
$(info "Including rust support")
15+
include project/virtual/rust.mk
16+
endif

project/virtual/rust.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# modules related to building rust support
2+
3+
MODULES += lib/rust_support
4+
5+
USE_RUST := 1
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2024 Travis Geiselbrecht
3+
*
4+
* Use of this source code is governed by a MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT
7+
*/
8+
#pragma once
9+
10+
#include <stdint.h>
11+
12+
// Set this flag if the UART is a debug UART, which routes input
13+
// directly into the console buffer if present.
14+
#define PL011_FLAG_DEBUG_UART (1u << 0)
15+
16+
struct pl011_config {
17+
uintptr_t base;
18+
uint32_t irq;
19+
uint32_t flag;
20+
};
21+
22+
// pl011 specific initialization routines called from platform code.
23+
// The driver will otherwise implement the uart_* interface.
24+
void pl011_init_early(int port, const struct pl011_config *config);
25+
void pl011_init(int port);

rust/dev-pl011/rules.mk

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
LOCAL_DIR := $(GET_LOCAL_DIR)
2+
MODULE := $(LOCAL_DIR)
3+
24
RUST_CRATES += $(LOCAL_DIR)
3-
MODULES += $(LOCAL_DIR)
5+
6+
# add any dependencies needed for rust support
7+
MODULE_DEPS += lib/rust_support
8+
9+
# make sure the local include directory is in the global include path
10+
include make/module.mk

0 commit comments

Comments
 (0)