File tree Expand file tree Collapse file tree 7 files changed +103
-0
lines changed Expand file tree Collapse file tree 7 files changed +103
-0
lines changed Original file line number Diff line number Diff line change 1+ # SPDX-License-Identifier: Apache-2.0
2+
3+ cmake_minimum_required (VERSION 3.20.0)
4+ find_package (Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} )
5+ project (ldc_hello_world)
6+
7+ target_sources (app PRIVATE src/main.c)
8+
9+ if (${ARCH} STREQUAL "posix" OR ${ARCH} STREQUAL "x86" )
10+ set (ldc_target i686-unknown-none-newlibeabi)
11+ elseif (CONFIG_CPU_CORTEX_M)
12+ if (CONFIG_CPU_CORTEX_M3)
13+ set (ldc_target thumbv7em-unknown-none-newlibeabi)
14+ else ()
15+ message (FATAL_ERROR "Unknown Cortex-M target" )
16+ endif ()
17+ elseif (CONFIG_RISCV)
18+ if (CONFIG_RISCV_ISA_RV32I)
19+ set (ldc_target riscv32-unknown-newlib-elf)
20+ else ()
21+ message (FATAL_ERROR "Unsupported riscv ISA" )
22+ endif ()
23+ else ()
24+ message (FATAL_ERROR "ARCH ${ARCH} not supported" )
25+ endif ()
26+
27+ include (ExternalProject)
28+ set (ldc_src_dir ${CMAKE_CURRENT_SOURCE_DIR} )
29+ ExternalProject_Add(
30+ ldc_project
31+ PREFIX ${CMAKE_CURRENT_BINARY_DIR}
32+ SOURCE_DIR ${ldc_src_dir}
33+ BUILD_IN_SOURCE 1
34+ BUILD_ALWAYS 1
35+ CONFIGURE_COMMAND ""
36+ BUILD_COMMAND
37+ dub
38+ build
39+ -f
40+ -b release
41+ --compiler=ldc2
42+ --arch=${ldc_target}
43+ INSTALL_COMMAND ""
44+ BUILD_BYPRODUCTS ${ldc_src_dir} /lib/libhelloworld.a
45+ )
46+
47+ add_library (ldc_lib STATIC IMPORTED GLOBAL )
48+ add_dependencies (
49+ ldc_lib
50+ ldc_project
51+ )
52+ set_target_properties (ldc_lib PROPERTIES IMPORTED_LOCATION ${ldc_src_dir} /lib/libhelloworld.a)
53+ target_link_libraries (app PUBLIC ldc_lib)
Original file line number Diff line number Diff line change 1+ name "hello_world"
2+ authors "Hiroki Noda"
3+ license "BSL-1.0"
4+ targetType "staticLibrary"
5+ targetPath "lib"
6+ targetName "helloworld"
7+ dependency "zephyr-core" path="../zephyr-core"
Original file line number Diff line number Diff line change 1+ default:
2+ {
3+ switches = [
4+ "-Os",
5+ "--betterC",
6+ "--float-abi=soft",
7+ "--relocation-model=static",
8+ "--defaultlib="
9+ ];
10+ post-switches = [
11+ "-I%%ldcbinarypath%%/../import",
12+ ];
13+ lib-dirs = [];
14+ }
Original file line number Diff line number Diff line change 1+ CONFIG_NEWLIB_LIBC=y
2+ CONFIG_POSIX_API=y
3+ CONFIG_MAIN_STACK_SIZE=2048
4+ CONFIG_LINKER_ORPHAN_SECTION_PLACE=y
Original file line number Diff line number Diff line change 1+ sample :
2+ description : hello world
3+ name : helloworld
4+ common :
5+ build_only : true
6+ platform_allow :
7+ - qemu_cortex_m3
8+ tests :
9+ app.default : {}
Original file line number Diff line number Diff line change 1+ import zephyr.core.stdc.stdio ;
2+
3+ extern (C ):
4+ nothrow :
5+ @nogc :
6+
7+ void d_main ()
8+ {
9+ printf(" Hello, World!\n " );
10+ }
Original file line number Diff line number Diff line change 1+ extern void d_main (void );
2+
3+ int main (void ) {
4+ d_main ();
5+ return 0 ;
6+ }
You can’t perform that action at this time.
0 commit comments