Skip to content

Commit 39d99c0

Browse files
committed
Merge branch 'main' of github.com:eth-easl/dandelionFunctionExamples into main
2 parents 79c65c7 + 5a91e9d commit 39d99c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4568
-345
lines changed

.github/workflows/cmake-multi-platform.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*.swp
22
.vscode
3-
build
3+
build*
44
target
55
*.check_cache
66
Cargo.lock

.gitmodules

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
[submodule "dandelionFunctionInterface"]
2-
path = dandelionFunctionInterface
3-
url = [email protected]:eth-easl/dandelionFunctionInterface.git
4-
branch = main
5-
[submodule "mlibc"]
6-
path = mlibc
7-
url = [email protected]:eth-easl/mlibc.git
8-
branch = dandelion
91
[submodule "wasm-compiler/rWasm"]
102
path = wasm-compiler/rWasm
113
url = https://github.com/eth-easl/rWasm

dandelionFunctionInterface

Lines changed: 0 additions & 1 deletion
This file was deleted.

functions/CMakeLists.txt

Lines changed: 76 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,111 @@
1-
set(CMAKE_VERSION 3.20)
1+
set(CMAKE_VERSION 3.23)
22
cmake_minimum_required(VERSION ${CMAKE_VERSION})
33

4+
project(function_examples LANGUAGES C CXX ASM)
5+
6+
include(FetchContent)
7+
48
# option to include libc-dependent examples
5-
option(USE_LIBC "Use libc" OFF)
9+
set(ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR} CACHE STRING "the architecture to build for")
10+
set(PLATFORM "debug" CACHE STRING "backend to build for")
11+
12+
if(NOT CMAKE_BUILD_TYPE)
13+
set(CMAKE_BUILD_TYPE "Debug")
14+
endif()
15+
16+
message(STATUS "Building ${CMAKE_BUILD_TYPE} for ${PLATFORM} on ${ARCHITECTURE}")
617

718
# prevent in-source builds
819
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
920
message(FATAL_ERROR "In-source build detected")
1021
endif()
1122

12-
project(function_examples LANGUAGES C CXX ASM)
13-
14-
if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
15-
else()
16-
message(FATAL_ERROR "Compiler not clang\n" "${CMAKE_C_COMPILER_ID}")
23+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
24+
set_property(CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_BINARY_DIR}/dandelion_sdk")
1725
endif()
1826

19-
# prepare mlibc
20-
if(USE_LIBC)
21-
# make cross file
22-
configure_file(cross_template.txt crossfile.txt)
23-
include(ExternalProject)
24-
ExternalProject_Add(mlibc
25-
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../mlibc
26-
CONFIGURE_COMMAND meson setup --cross-file ${CMAKE_CURRENT_BINARY_DIR}/crossfile.txt -Dprefix=<INSTALL_DIR> <BINARY_DIR> <SOURCE_DIR>
27-
BUILD_COMMAND ninja -C <BINARY_DIR>
28-
# Enable when working on the libc to make sure it is freshly compiled
29-
# BUILD_ALWAYS TRUE
30-
INSTALL_COMMAND meson install -C <BINARY_DIR> --no-rebuild --only-changed --quiet
31-
)
32-
ExternalProject_Get_Property(mlibc INSTALL_DIR)
33-
set(MLIBC_INSTALL_DIR ${INSTALL_DIR})
34-
35-
add_library(dlibc OBJECT IMPORTED)
36-
add_dependencies(dlibc mlibc)
37-
set(MLIBC_OBJ
38-
"${MLIBC_INSTALL_DIR}/lib/crt1.o"
39-
"${MLIBC_INSTALL_DIR}/lib/crti.o"
40-
"${MLIBC_INSTALL_DIR}/lib/crtn.o")
41-
set_target_properties(dlibc PROPERTIES IMPORTED_OBJECTS "${MLIBC_OBJ}")
42-
file(MAKE_DIRECTORY "${MLIBC_INSTALL_DIR}/include")
43-
target_include_directories(dlibc INTERFACE "${MLIBC_INSTALL_DIR}/include")
44-
set(MLIBC_LIBS
45-
"${MLIBC_INSTALL_DIR}/lib/libc.a"
46-
"${MLIBC_INSTALL_DIR}/lib/libcrypt.a"
47-
"${MLIBC_INSTALL_DIR}/lib/libdl.a"
48-
"${MLIBC_INSTALL_DIR}/lib/libm.a"
49-
"${MLIBC_INSTALL_DIR}/lib/libpthread.a"
50-
"${MLIBC_INSTALL_DIR}/lib/libresolv.a"
51-
"${MLIBC_INSTALL_DIR}/lib/librt.a"
52-
"${MLIBC_INSTALL_DIR}/lib/libutil.a"
53-
${COMP_RTLIB}
54-
)
55-
target_link_libraries(dlibc INTERFACE ${RUNTIME_LIB} ${MLIBC_LIBS})
56-
target_link_options(dlibc INTERFACE -nostdlib)
57-
endif()
27+
# setup build toolchain
28+
FetchContent_Declare(
29+
dandelion_sdk
30+
DOWNLOAD_COMMAND gh release download latest -R eth-easl/dandelionFunctionInterface -p "*${CMAKE_BUILD_TYPE}_${PLATFORM}_${ARCHITECTURE}.tar.gz"
31+
COMMAND tar -xzf "dandelion_sdk_${CMAKE_BUILD_TYPE}_${PLATFORM}_${ARCHITECTURE}.tar.gz" -C ${CMAKE_BINARY_DIR}
32+
)
33+
FetchContent_MakeAvailable(dandelion_sdk)
34+
35+
execute_process(
36+
COMMAND ${CMAKE_C_COMPILER} -print-file-name=include
37+
OUTPUT_STRIP_TRAILING_WHITESPACE
38+
OUTPUT_VARIABLE COMPILER_RUNTIME_INCLUDE
39+
COMMAND_ERROR_IS_FATAL ANY
40+
)
5841

42+
add_subdirectory("${CMAKE_BINARY_DIR}/dandelion_sdk" "${CMAKE_BINARY_DIR}/dandelion_sdk_build")
43+
44+
if(CMAKE_BUILD_TYPE MATCHES "Debug")
45+
add_compile_options(-gdwarf-4)
46+
endif()
5947

6048
# cheri compile flags
61-
if("${DANDELION_PLATFORM}" STREQUAL "cheri")
49+
if("${PLATFORM}" STREQUAL "cheri")
6250
add_compile_options(-march=morello -mabi=aapcs)
6351
add_link_options(-march=morello -mabi=aapcs -fuse-ld=lld -Xlinker --image-base=0x10000)
6452
get_property(CROSS_COMPILE_OPTIONS DIRECTORY PROPERTY COMPILE_OPTIONS)
6553
string(REPLACE ";" " " CROSS_COMPILE_OPTIONS "${CROSS_COMPILE_OPTIONS}")
6654
get_property(CROSS_LINK_OPTIONS DIRECTORY PROPERTY LINK_OPTIONS)
6755
string(REPLACE ";" " " CROSS_LINK_OPTIONS "${CROSS_LINK_OPTIONS}")
6856
# WebAssembly flags
69-
elseif("${DANDELION_PLATFORM}" STREQUAL "wasm")
57+
elseif("${PLATFORM}" STREQUAL "wasm")
7058
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --verbose -target wasm32-unknown-unknown -Wl,--export-all -Wl,--import-undefined -Wl,--import-memory")
7159
else()
7260
# currently still want to set the base image lower for all other images, if some don't want make special case
7361
add_link_options(-fuse-ld=lld -Xlinker --image-base=0x10000)
7462
endif()
7563

76-
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../dandelionFunctionInterface" functionInterface)
77-
7864
# add folders with function examples
7965
# add_subdirectory(access)
8066
add_subdirectory(basic)
8167
add_subdirectory(busy)
8268
add_subdirectory(matmac)
8369
add_subdirectory(matmul)
8470
add_subdirectory(example_app_nolibc)
71+
8572
# dependent on dlibc
86-
if(USE_LIBC)
87-
# add_subdirectory(image_processing)
88-
add_subdirectory(dirigent_busy)
89-
add_subdirectory(example_app)
90-
add_subdirectory(files)
91-
add_subdirectory(stdio)
92-
endif()
73+
add_subdirectory(dirigent_busy)
74+
add_subdirectory(example_app)
75+
add_subdirectory(files)
76+
add_subdirectory(stdio)
77+
add_subdirectory(stdio_cxx)
78+
# add_subdirectory(example_app_hybrid)
79+
add_subdirectory(compression)
80+
add_subdirectory(busy_libc)
81+
add_subdirectory(busy_hybrid)
82+
83+
# set(CONFIG_FLAG "--config ${CMAKE_BINARY_DIR}/dandelion.cfg")
84+
# set(CONFIG_FLAGXX "--config ${CMAKE_BINARY_DIR}/dandelion++.cfg")
85+
86+
# include(ExternalProject)
87+
# ExternalProject_Add(
88+
# llvmproject
89+
# PREFIX llvmproject
90+
# GIT_REPOSITORY https://github.com/llvm/llvm-project
91+
# GIT_TAG release/18.x
92+
# SOURCE_SUBDIR llvm
93+
# UPDATE_DISCONNECTED 1
94+
# INSTALL_DIR ${CMAKE_BINARY_DIR}/llvm
95+
# LIST_SEPARATOR ","
96+
# CMAKE_ARGS
97+
# -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
98+
# -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
99+
# -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
100+
# -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
101+
# -DCMAKE_SYSTEM_NAME=Generic
102+
# -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
103+
# -DCMAKE_C_FLAGS:STRING=${CONFIG_FLAG}
104+
# -DCMAKE_CXX_FLAGS:STRING=${CONFIG_FLAGXX}
105+
# -DLLVM_ENABLE_PROJECTS=clang,lld
106+
# -DLLVM_TARGETS_TO_BUILD=AArch64,X86
107+
# -DBUILD_SHARED_LIBS=OFF
108+
# -DLLVM_ENABLE_PIC=OFF
109+
# -DLLVM_ENABLE_THREADS=OFF
110+
# EXCLUDE_FROM_ALL TRUE
111+
# )

functions/README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@ Some functions depend on the function interface directly while others use it
66
through mlibc.
77

88
# Building the C functions
9-
The cmake build process will build the function interface, libc and the functions.
10-
To do so cmake needs to know that it needs to use the cross compile file dandelion.
11-
Additionally, cmake and needs to know the platform to build for (cheri, mmu_freebsd, mmu_linux).
9+
The cmake build process will build the functions based on the latest version of the dandelion SDK.
10+
For this cmake meeds to know the platform to build for (cheri, mmu_freebsd, mmu_linux, debug) and architecture (x86_64, aarch64)
11+
The build type can be Release or Debug.
1212
From the top folder functions can be built with:
1313
```
1414
mkdir build
1515
cd build
16-
cmake -DCMAKE_TOOLCHAIN_FILE=../functions/dandelion.cmake -DDANDELION_PLATFORM=<platform> -DTARGET_CPU=<target arch> ../functions
16+
cmake -DPLATFORM=<platform> -DARCHITECTURE=<target arch> -DCMAKE_BUILD_TYPE-<type> ../functions
1717
```
18-
The mlibc build currently only seems to work with clang.
19-
To set this up set CC=clang and CXX=clang++ additionally set LDFLAGS=-fuse-ld=lld
20-
21-
## Building dlibc
22-
To turn on building of libc enable the cmake option with `-DUSE_LIBC=on`

0 commit comments

Comments
 (0)