Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions hello_world/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(ldc_hello_world)

target_sources(app PRIVATE src/main.c)

if(${ARCH} STREQUAL "posix" OR ${ARCH} STREQUAL "x86")
set(ldc_target i686-unknown-none-newlibeabi)
elseif(CONFIG_CPU_CORTEX_M)
if(CONFIG_CPU_CORTEX_M3)
set(ldc_target thumbv7em-unknown-none-newlibeabi)
else()
message(FATAL_ERROR "Unknown Cortex-M target")
endif()
elseif(CONFIG_RISCV)
if(CONFIG_RISCV_ISA_RV32I)
set(ldc_target riscv32-unknown-newlib-elf)
else()
message(FATAL_ERROR "Unsupported riscv ISA")
endif()
else()
message(FATAL_ERROR "ARCH ${ARCH} not supported")
endif()

include(ExternalProject)
set(ldc_src_dir ${CMAKE_CURRENT_SOURCE_DIR})
ExternalProject_Add(
ldc_project
PREFIX ${CMAKE_CURRENT_BINARY_DIR}
SOURCE_DIR ${ldc_src_dir}
BUILD_IN_SOURCE 1
BUILD_ALWAYS 1
CONFIGURE_COMMAND ""
BUILD_COMMAND
dub
build
-f
-b release
--compiler=ldc2
--arch=${ldc_target}
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${ldc_src_dir}/lib/libhelloworld.a
)

add_library(ldc_lib STATIC IMPORTED GLOBAL)
add_dependencies(
ldc_lib
ldc_project
)
set_target_properties(ldc_lib PROPERTIES IMPORTED_LOCATION ${ldc_src_dir}/lib/libhelloworld.a)
target_link_libraries(app PUBLIC ldc_lib)
7 changes: 7 additions & 0 deletions hello_world/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name "hello_world"
authors "Hiroki Noda"
license "BSL-1.0"
targetType "staticLibrary"
targetPath "lib"
targetName "helloworld"
dependency "zephyr-core" path="../zephyr-core"
14 changes: 14 additions & 0 deletions hello_world/ldc2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
default:
{
switches = [
"-Os",
"--betterC",
"--float-abi=soft",
"--relocation-model=static",
"--defaultlib="
];
post-switches = [
"-I%%ldcbinarypath%%/../import",
];
lib-dirs = [];
}
4 changes: 4 additions & 0 deletions hello_world/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_NEWLIB_LIBC=y
CONFIG_POSIX_API=y
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_LINKER_ORPHAN_SECTION_PLACE=y
9 changes: 9 additions & 0 deletions hello_world/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sample:
description: hello world
name: helloworld
common:
build_only: true
platform_allow:
- qemu_cortex_m3
tests:
app.default: {}
10 changes: 10 additions & 0 deletions hello_world/src/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import zephyr.core.stdc.stdio;

extern(C):
nothrow:
@nogc:

void d_main()
{
printf("Hello, World!\n");
}
6 changes: 6 additions & 0 deletions hello_world/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extern void d_main(void);

int main(void) {
d_main();
return 0;
}