2
2
3
3
cmake_minimum_required (VERSION 3.13.1 )
4
4
5
- include ($ENV{ZEPHYR_BASE} /cmake/app/boilerplate.cmake NO_POLICY_SCOPE )
6
- project (hello_world )
7
-
8
- target_sources (app PRIVATE src/main.c rust_obj.obj )
9
-
10
5
# Use a clang_target known to clang so headers will be processed correctly with
11
6
# bindgen. rust_target may point to a custom json target.
12
7
if (${ARCH} STREQUAL "posix" OR ${ARCH} STREQUAL "x86" )
@@ -42,8 +37,13 @@ add_custom_command(OUTPUT ${zephyr_bindgen}
42
37
)
43
38
44
39
set (rust_src_dir ${CMAKE_CURRENT_SOURCE_DIR} /rust-app )
45
- set (rust_build_dir ${CMAKE_CURRENT_BINARY_DIR} /rust-app )
46
- set (rust_staticlib ${rust_build_dir} /${rust_target}/release/librust_app.a )
40
+ set (rust_sysroot ${CMAKE_CURRENT_BINARY_DIR} /sysroot )
41
+ set (rust_sysroot_build ${CMAKE_CURRENT_BINARY_DIR} /sysroot-build )
42
+ set (rust_app_build ${CMAKE_CURRENT_BINARY_DIR} /app )
43
+ set (rust_staticlib ${rust_app_build} /${rust_target}/release/librust_app.a )
44
+ if (NOT DEFINED CARGO_MANIFEST )
45
+ set (CARGO_MANIFEST ${CMAKE_SOURCE_DIR} /Cargo.toml )
46
+ endif ()
47
47
48
48
zephyr_get_include_directories_for_lang_as_string ( C includes )
49
49
zephyr_get_compile_definitions_for_lang_as_string ( C definitions )
@@ -56,7 +56,7 @@ include(ExternalProject)
56
56
57
57
ExternalProject_Add (
58
58
rust_project
59
- PREFIX ${rust_build_dir }
59
+ PREFIX ${CMAKE_CURRENT_BINARY_DIR }
60
60
SOURCE_DIR ${rust_src_dir}
61
61
BUILD_IN_SOURCE 1
62
62
BUILD_ALWAYS 1
@@ -67,19 +67,21 @@ ExternalProject_Add(
67
67
"ZEPHYR_BINDGEN=${zephyr_bindgen} "
68
68
"CONFIG_USERSPACE=${CONFIG_USERSPACE} "
69
69
"TARGET_CFLAGS=${external_project_cflags} --target=${clang_target} "
70
- "SYSROOT=${rust_build_dir} /sysroot"
70
+ "SYSROOT=${rust_sysroot} "
71
+ "SYSROOT_BUILD=${rust_sysroot_build} "
72
+ "APP_BUILD=${rust_app_build} "
71
73
"RUST_TARGET_PATH=${rust_src_dir} "
72
- "CARGO_TARGET_DIR=${rust_build_dir} "
73
74
"RUST_TARGET=${rust_target} "
75
+ "CARGO_MANIFEST=${CARGO_MANIFEST} "
74
76
./build.sh
75
77
INSTALL_COMMAND ""
76
78
BUILD_BYPRODUCTS ${rust_staticlib}
77
79
)
78
80
79
- add_library (rust_obj OBJECT syscall-thunk.c rust-smem.c )
80
- target_link_libraries (rust_obj zephyr_interface )
81
+ add_library (rust_c OBJECT syscall-thunk.c rust-smem.c )
82
+ target_link_libraries (rust_c zephyr_interface )
81
83
# High level target that means all headers have been generated
82
- add_dependencies (rust_obj offsets_h )
84
+ add_dependencies (rust_c offsets_h )
83
85
84
86
# Relocatable single object library containing all Rust code. This allows using
85
87
# a linker script during this link to rename sections, putting data/bss in the
@@ -91,17 +93,21 @@ if(CONFIG_USERSPACE)
91
93
endif ()
92
94
set (RUST_OBJ_CFLAGS ${CMAKE_C_FLAGS} )
93
95
separate_arguments (RUST_OBJ_CFLAGS )
96
+ set (rust_obj ${CMAKE_CURRENT_BINARY_DIR} /rust_obj.obj )
94
97
add_custom_command (
95
- OUTPUT rust_obj.obj
98
+ OUTPUT ${ rust_obj}
96
99
COMMAND ${CMAKE_C_COMPILER} ${RUST_OBJ_CFLAGS}
97
100
-nostdlib
98
101
-static
99
102
-no-pie
100
103
-Wl,-r
101
104
${rust_ldscript}
102
105
-Wl,--whole-archive ${rust_staticlib}
103
- -Wl,--no-whole-archive $< TARGET_OBJECTS:rust_obj >
106
+ -Wl,--no-whole-archive $< TARGET_OBJECTS:rust_c >
104
107
-o rust_obj.obj
105
- DEPENDS ${rust_staticlib} $< TARGET_OBJECTS:rust_obj >
108
+ DEPENDS ${rust_staticlib} $< TARGET_OBJECTS:rust_c >
106
109
COMMAND_EXPAND_LISTS
107
110
)
111
+ add_custom_target (rust_final DEPENDS ${rust_obj} )
112
+ zephyr_library_import (rust ${rust_obj} )
113
+ add_dependencies (rust rust_final )
0 commit comments