From 6197acf3b2365c847551f145513072db36b438fd Mon Sep 17 00:00:00 2001 From: servostar Date: Mon, 27 May 2024 21:22:06 +0200 Subject: [PATCH] fixed: llvm dependencies in sdk --- CMakeLists.txt | 16 +++++++++++++--- run-docker-build.sh | 2 +- sdk/Dockerfile | 2 +- src/llvm/backend.c | 16 +++++++--------- tests/llvm/CMakeLists.txt | 5 +++++ 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 61e1ed0..7672ede 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE} # Setup Glib 2.0 # # ------------------------------------------------ # +include(FindPkgConfig) find_package(PkgConfig REQUIRED) pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0) @@ -81,8 +82,18 @@ pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0) # LLVM backend # # ------------------------------------------------ # -find_package(PkgConfig REQUIRED) -pkg_search_module(LLVM REQUIRED IMPORTED_TARGET llvm17) +# Fetch LLVM link configuration +execute_process(COMMAND llvm-config --libs all + OUTPUT_VARIABLE LLVM_LIBS) +# Strip whitespace from output +string(STRIP "${LLVM_LIBS}" LLVM_LIBS) +# Link all targets to LLVM +link_libraries(${LLVM_LIBS}) + +execute_process(COMMAND llvm-config --includedir + OUTPUT_VARIABLE LLVM_INCLUDE_DIR) +string(STRIP "${LLVM_INCLUDE_DIR}" LLVM_INCLUDE_DIR) +include_directories(${LLVM_INCLUDE_DIR}) # ------------------------------------------------ # # Source # @@ -90,7 +101,6 @@ pkg_search_module(LLVM REQUIRED IMPORTED_TARGET llvm17) include_directories(${PROJECT_SOURCE_DIR}/src) include_directories(PRIVATE ${GLIB_INCLUDE_DIRS}) -include_directories(PRIVATE ${LLVM_INCLUDE_DIRS}) file(GLOB_RECURSE SOURCE_FILES src/*.c) diff --git a/run-docker-build.sh b/run-docker-build.sh index aaec9c6..0028067 100755 --- a/run-docker-build.sh +++ b/run-docker-build.sh @@ -47,7 +47,7 @@ echo "+--------------------------------------+" echo "| RUNNING check test |" echo "+--------------------------------------+" -docker run servostar/gemstone:devkit-"$SDK" sh run-check-test.sh +docker run --rm --name "devkit-$SDK-check-test"- servostar/gemstone:devkit-"$SDK" sh run-check-test.sh if [ ! $? -eq 0 ]; then echo "===> failed to run build or checks" exit 1 diff --git a/sdk/Dockerfile b/sdk/Dockerfile index fb63cad..1cba1d3 100644 --- a/sdk/Dockerfile +++ b/sdk/Dockerfile @@ -5,7 +5,7 @@ LABEL description="base image for building the gemstone programming language com LABEL website="https://github.com/Servostar/gemstone" # install dependencies -RUN apk add build-base gcc make cmake bison flex git python3 graphviz glib glib-dev llvm17-dev +RUN apk add build-base gcc make cmake bison flex git python3 graphviz glib glib-dev llvm17-libs llvm17-dev # create user for build RUN adduser --disabled-password lorang diff --git a/src/llvm/backend.c b/src/llvm/backend.c index 04c23f0..6bd5997 100644 --- a/src/llvm/backend.c +++ b/src/llvm/backend.c @@ -1,12 +1,12 @@ #include +#include #include #include #include -#include -#include #include #include +#include Target create_native_target() { DEBUG("creating native target..."); @@ -34,9 +34,7 @@ Target create_native_target() { return target; } -Target create_target_from_config() { - PANIC("NOT IMPLEMENTED"); -} +Target create_target_from_config() { PANIC("NOT IMPLEMENTED"); } static void delete_string(String string) { DEBUG("deleting string..."); @@ -59,9 +57,7 @@ void delete_target(Target target) { delete_string(target.triple); } -typedef enum LLVMBackendError_t { - UnresolvedImport -} LLVMBackendError; +typedef enum LLVMBackendError_t { UnresolvedImport } LLVMBackendError; static BackendError llvm_backend_codegen(const Module* unit, void** output) { return parse_module(unit, output); @@ -76,7 +72,9 @@ static BackendError llvm_backend_codegen_deinit(void) { } void llvm_backend_init() { - BackendError err = set_backend(&llvm_backend_codegen_init, &llvm_backend_codegen_deinit, &llvm_backend_codegen, "LLVM"); + BackendError err = + set_backend(&llvm_backend_codegen_init, &llvm_backend_codegen_deinit, + &llvm_backend_codegen, "LLVM"); if (err.kind != Success) { PANIC("unable to init llvm backend: %ld", err); diff --git a/tests/llvm/CMakeLists.txt b/tests/llvm/CMakeLists.txt index e4dcdc9..1fc14cc 100644 --- a/tests/llvm/CMakeLists.txt +++ b/tests/llvm/CMakeLists.txt @@ -19,6 +19,11 @@ string(STRIP "${LLVM_LIBS}" LLVM_LIBS) # Link all targets to LLVM link_libraries(${LLVM_LIBS}) +execute_process(COMMAND llvm-config --includedir + OUTPUT_VARIABLE LLVM_INCLUDE_DIR) +string(STRIP "${LLVM_INCLUDE_DIR}" LLVM_INCLUDE_DIR) +include_directories(${LLVM_INCLUDE_DIR}) + # ------------------------------------------------------- # # CTEST 1 # test llvm backend codegen for global variables