Skip to content

Commit c23f46f

Browse files
committed
cmake: Add rustdoc target
Add a target to the build `rustdoc` that will generate the rust documentation. The documentation will be placed in a target-specific directory under `build/rust/target/...`. There is some duplication in the cmake file, as I can't figure out how to factor this out into a variable and maintain the proper quoting of the space separated strings. Signed-off-by: David Brown <[email protected]>
1 parent d537adc commit c23f46f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

CMakeLists.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ WRAPPER_FILE = \"${WRAPPER_FILE}\"
143143
${config_paths}
144144
")
145145

146+
# The block of environment variables below could theoretically be captured in a variable, but this
147+
# seems "challenging" in CMake (to be polite), as many of these contain spaces, and the quoting
148+
# rules in CMake are inconsistent, at best.
149+
# TODO: Figure out how to factor these out.
150+
146151
# The library is built by invoking Cargo.
147152
add_custom_command(
148153
OUTPUT ${DUMMY_FILE}
@@ -183,6 +188,45 @@ ${config_paths}
183188
kobj_types_h_target
184189
)
185190

191+
# Command to generate the rust docs. As mentioned above, the whole environment is duplicated, so
192+
# it is important to keep this in sync with the above.
193+
add_custom_command(
194+
OUTPUT generate_rust_docs
195+
COMMAND
196+
${CMAKE_COMMAND} -E
197+
env BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}
198+
ZEPHYR_BASE=${ZEPHYR_BASE}
199+
DOTCONFIG=${DOTCONFIG}
200+
ZEPHYR_DTS=${ZEPHYR_DTS}
201+
INCLUDE_DIRS="${include_dirs}"
202+
INCLUDE_DEFINES="${include_defines}"
203+
WRAPPER_FILE="${WRAPPER_FILE}"
204+
cargo doc
205+
${rust_build_type_arg}
206+
207+
# Override the features according to the shield given. For a general case,
208+
# this will need to come from a variable or argument.
209+
# TODO: This needs to be passed in.
210+
# --no-default-features
211+
# --features ${SHIELD_FEATURE}
212+
213+
# Set a replacement so that packages can just use `zephyr-sys` as a package
214+
# name to find it.
215+
${command_paths}
216+
--target ${RUST_TARGET}
217+
--target-dir ${CARGO_TARGET_DIR}
218+
COMMENT "Building Rust documentation"
219+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
220+
)
221+
222+
add_custom_target(rustdoc
223+
DEPENDS generate_rust_docs
224+
# The variables, defined at the top level, don't seem to be accessible here.
225+
syscall_list_h_target
226+
driver_validation_h_target
227+
kobj_types_h_target
228+
)
229+
186230
# Linking with the <rt_library> (`$<TARGET_PROPERTY:linker,rt_library>`).
187231
# -lgcc / -lcompiler_rt depending on toolchain, linker, and runtime library configuration.
188232
# In general this shouldn't be needed, as the runtime libary is generally linked late, but

0 commit comments

Comments
 (0)