Skip to content

Commit 21877f5

Browse files
authored
Merge pull request #9 from kubo39/hello-world-example
Add hello world example
2 parents 0888ff3 + f7ff810 commit 21877f5

File tree

7 files changed

+103
-0
lines changed

7 files changed

+103
-0
lines changed

Diff for: hello_world/CMakeLists.txt

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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)

Diff for: hello_world/dub.sdl

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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"

Diff for: hello_world/ldc2.conf

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}

Diff for: hello_world/prj.conf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_NEWLIB_LIBC=y
2+
CONFIG_POSIX_API=y
3+
CONFIG_MAIN_STACK_SIZE=2048
4+
CONFIG_LINKER_ORPHAN_SECTION_PLACE=y

Diff for: hello_world/sample.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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: {}

Diff for: hello_world/src/app.d

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

Diff for: hello_world/src/main.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extern void d_main(void);
2+
3+
int main(void) {
4+
d_main();
5+
return 0;
6+
}

0 commit comments

Comments
 (0)