diff --git a/.env b/.env new file mode 100644 index 0000000..e09c958 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +SDK=0.2.4-alpine-3.19.1 \ No newline at end of file diff --git a/.github/workflows/build-check-sdk.yaml b/.github/workflows/build-check-sdk.yaml index b17b734..d71dcf8 100644 --- a/.github/workflows/build-check-sdk.yaml +++ b/.github/workflows/build-check-sdk.yaml @@ -1,14 +1,14 @@ name: "Build check gemstone in SDK" run-name: SDK build check to ${{ inputs.deploy_target }} by @${{ github.actor }} on: [push, pull_request] -env: - SDK: 0.2.3-alpine-3.19.1 jobs: build-check-sdk: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Setup repository + run: git submodule init && git submodule update - name: Setup SDK - run: docker pull servostar/gemstone:sdk-"$SDK" && docker build --tag gemstone:devkit-"$SDK" . + run: source ./.env && docker pull servostar/gemstone:sdk-"$SDK" - name: Compile - run: docker run gemstone:devkit-"$SDK" sh run-check-test.sh + run: set -a && source ./.env && sh run-docker-build.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 213143c..b304447 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ cmake_minimum_required(VERSION 3.15...3.25) # Header must be included this way: #include # # ├─ res +# ├─ dep +# │ └─ klib # ├─ src # │ ├─ lex # │ │ └─ lexer.l @@ -68,17 +70,27 @@ add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE} COMMENT "generate C source file for parser" VERBATIM) +# ------------------------------------------------ # +# Setup Glib 2.0 # +# ------------------------------------------------ # + +find_package(PkgConfig REQUIRED) +pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0) + # ------------------------------------------------ # # Source # # ------------------------------------------------ # +include_directories(${PROJECT_SOURCE_DIR}/src) +include_directories(PRIVATE ${GLIB_INCLUDE_DIRS}) + file(GLOB_RECURSE SOURCE_FILES src/*.c) # define default compile flags if (MSVC) set(FLAGS /Wall /W3 /permissive) else() - set(FLAGS -Wall -Wextra -Wconversion -Wpedantic) + set(FLAGS -Wall -Wextra -Wpedantic) endif() # ------------------------------------------------ # @@ -95,6 +107,8 @@ set_target_properties(release OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/release) +target_link_libraries(release PkgConfig::GLIB) + # FIXME: cannot compile with /O2 because of /RTC1 flag if (MSVC) set(RELEASE_FLAGS) @@ -127,6 +141,8 @@ set_target_properties(debug OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/debug) +target_link_libraries(debug PkgConfig::GLIB) + if (MSVC) set(DEBUG_FLAGS /DEBUG) else() @@ -156,6 +172,8 @@ set_target_properties(check OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/check) +target_link_libraries(check PkgConfig::GLIB) + if (MSVC) set(CHECK_FLAGS /DEBUG /WX) else() diff --git a/Dockerfile b/Dockerfile index a8c2f7f..68265d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM servostar/gemstone:sdk-0.2.3-alpine-3.19.1 +FROM servostar/gemstone:sdk-0.2.4-alpine-3.19.1 LABEL authors="servostar" -LABEL version="0.2.3" +LABEL version="0.2.4" LABEL description="docker image for setting up the build pipeline on SDK" LABEL website="https://github.com/Servostar/gemstone" @@ -8,5 +8,7 @@ COPY --chown=lorang src /home/lorang/src COPY --chown=lorang tests /home/lorang/tests COPY --chown=lorang CMakeLists.txt /home/lorang/ COPY --chown=lorang run-check-test.sh /home/lorang/ +COPY --chown=lorang .env /home/lorang/ +COPY --chown=lorang run-docker-build.sh /home/lorang/ RUN cmake . diff --git a/run-check-test.sh b/run-check-test.sh index a2a3ab4..bd7e5cc 100644 --- a/run-check-test.sh +++ b/run-check-test.sh @@ -9,6 +9,8 @@ echo "+--------------------------------------+" echo "| BUILDING all TARGETS |" echo "+--------------------------------------+" +cmake . + make -B if [ ! $? -eq 0 ]; then echo "===> failed to build targets" diff --git a/run-docker-build.sh b/run-docker-build.sh new file mode 100755 index 0000000..aaec9c6 --- /dev/null +++ b/run-docker-build.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env sh + +# Author: Sven Vogel +# Created: 17.05.2024 +# Description: Builds the Dockerfile for SDK and DEVKIT + +echo "+--------------------------------------+" +echo "| CHECKING prelude |" +echo "+--------------------------------------+" + +if [ -z "$SDK" ]; then + echo "no SDK specified, sourcing .env" + source ./.env + + if [ -z "$SDK" ]; then + echo "no SDK specified" + exit 1 + else + echo "using SDK $SDK" + fi + +else + echo "using SDK $SDK" +fi + +echo "+--------------------------------------+" +echo "| BUILDING SDK |" +echo "+--------------------------------------+" + +docker build --tag servostar/gemstone:sdk-"$SDK" sdk/. +if [ ! $? -eq 0 ]; then + echo "===> failed to build sdk" + exit 1 +fi + +echo "+--------------------------------------+" +echo "| BUILDING DEVKIT |" +echo "+--------------------------------------+" + +docker build --tag servostar/gemstone:devkit-"$SDK" . +if [ ! $? -eq 0 ]; then + echo "===> failed to build devkit" + exit 1 +fi + +echo "+--------------------------------------+" +echo "| RUNNING check test |" +echo "+--------------------------------------+" + +docker run servostar/gemstone:devkit-"$SDK" sh run-check-test.sh +if [ ! $? -eq 0 ]; then + echo "===> failed to run build or checks" + exit 1 +fi + +echo "+--------------------------------------+" +echo "| DONE |" +echo "+--------------------------------------+" diff --git a/sdk/Dockerfile b/sdk/Dockerfile index aae7438..b5523b3 100644 --- a/sdk/Dockerfile +++ b/sdk/Dockerfile @@ -1,11 +1,11 @@ FROM alpine:3.19.1 LABEL authors="servostar" -LABEL version="0.2.3" +LABEL version="0.2.4" LABEL description="base image for building the gemstone programming language compiler" LABEL website="https://github.com/Servostar/gemstone" # install dependencies -RUN apk add build-base gcc make cmake bison flex git python3 graphviz +RUN apk add build-base gcc make cmake bison flex git python3 graphviz glib glib-dev # create user for build RUN adduser --disabled-password lorang diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b5c1111..1228d2b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,4 +8,5 @@ set(CTEST_BINARY_DIRECTORY ${PROJECT_BINARY_DIR}/tests) add_subdirectory(logging) add_subdirectory(input_file) -add_subdirectory(ast) \ No newline at end of file +add_subdirectory(ast) +add_subdirectory(glib) \ No newline at end of file diff --git a/tests/glib/CMakeLists.txt b/tests/glib/CMakeLists.txt new file mode 100644 index 0000000..e3ede27 --- /dev/null +++ b/tests/glib/CMakeLists.txt @@ -0,0 +1,22 @@ +include(CTest) + +include_directories(${PROJECT_SOURCE_DIR}/src) +include_directories(PRIVATE ${GLIB_INCLUDE_DIRS}) + +find_package(PkgConfig REQUIRED) +pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0) + +# ------------------------------------------------------- # +# CTEST 1 +# test Glib's hashmap + +add_executable(glib_hashmap + glib_hashmap.c) +set_target_properties(glib_hashmap + PROPERTIES + OUTPUT_NAME "glib_hashmap" + RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/glib) +target_link_libraries(glib_hashmap PkgConfig::GLIB) +add_test(NAME glib_hashmap + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND ${GEMSTONE_BINARY_DIR}/tests/glib/glib_hashmap) diff --git a/tests/glib/glib_hashmap.c b/tests/glib/glib_hashmap.c new file mode 100644 index 0000000..116df77 --- /dev/null +++ b/tests/glib/glib_hashmap.c @@ -0,0 +1,27 @@ + +#include + +int main(int argc, char* argv[]) { + + GHashTable* map = g_hash_table_new(g_str_hash, g_str_equal); + + for (int i = 0; i < argc; i++) { + int* index = malloc(sizeof(int)); + + *index = i; + + g_hash_table_insert(map, argv[i], index); + } + + for (int i = 0; i < argc; i++) { + int* index = (int*) g_hash_table_lookup(map, argv[i]); + + g_hash_table_remove(map, argv[i]); + + free(index); + } + + g_hash_table_destroy(map); + + return 0; +}