From 6d03b97b9c5da64ea8d47ef412007692581defda Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 17 May 2024 15:39:07 +0200 Subject: [PATCH 01/14] added klib as external library --- .env | 1 + .github/workflows/build-check-sdk.yaml | 6 ++-- CMakeLists.txt | 27 +++++++++++++- Dockerfile | 5 +-- dep/klib | 1 + run-docker-build.sh | 50 ++++++++++++++++++++++++++ sdk/Dockerfile | 4 +-- tests/CMakeLists.txt | 3 +- tests/klib/CMakeLists.txt | 20 +++++++++++ tests/klib/hashmap.c | 36 +++++++++++++++++++ 10 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 .env create mode 160000 dep/klib create mode 100755 run-docker-build.sh create mode 100644 tests/klib/CMakeLists.txt create mode 100644 tests/klib/hashmap.c 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..e7a9561 100644 --- a/.github/workflows/build-check-sdk.yaml +++ b/.github/workflows/build-check-sdk.yaml @@ -1,14 +1,12 @@ 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 SDK - run: docker pull servostar/gemstone:sdk-"$SDK" && docker build --tag gemstone:devkit-"$SDK" . + run: docker pull servostar/gemstone:sdk-"$SDK" - name: Compile - run: docker run gemstone:devkit-"$SDK" sh run-check-test.sh + run: run-check-test.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 213143c..a0cbd38 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,34 @@ add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE} COMMENT "generate C source file for parser" VERBATIM) +# ------------------------------------------------ # +# Klib # +# ------------------------------------------------ # + +file(GLOB KLIB_SOURCE_FILES ${PROJECT_SOURCE_DIR}/dep/klib/*.c) + +add_library(klib + STATIC + ${KLIB_SOURCE_FILES}) + +set_target_properties(klib + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/dep) + # ------------------------------------------------ # # Source # # ------------------------------------------------ # +include_directories(${PROJECT_SOURCE_DIR}/src) +include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/dep) + 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 +114,8 @@ set_target_properties(release OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/release) +target_link_libraries(release klib) + # FIXME: cannot compile with /O2 because of /RTC1 flag if (MSVC) set(RELEASE_FLAGS) @@ -127,6 +148,8 @@ set_target_properties(debug OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/debug) +target_link_libraries(debug klib) + if (MSVC) set(DEBUG_FLAGS /DEBUG) else() @@ -156,6 +179,8 @@ set_target_properties(check OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/check) +target_link_libraries(check klib) + if (MSVC) set(CHECK_FLAGS /DEBUG /WX) else() diff --git a/Dockerfile b/Dockerfile index a8c2f7f..0693935 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,11 @@ -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" COPY --chown=lorang src /home/lorang/src +COPY --chown=lorang dep /home/lorang/dep COPY --chown=lorang tests /home/lorang/tests COPY --chown=lorang CMakeLists.txt /home/lorang/ COPY --chown=lorang run-check-test.sh /home/lorang/ diff --git a/dep/klib b/dep/klib new file mode 160000 index 0000000..4988b65 --- /dev/null +++ b/dep/klib @@ -0,0 +1 @@ +Subproject commit 4988b65b9c90473d155268c8ee15f3aad546406b diff --git a/run-docker-build.sh b/run-docker-build.sh new file mode 100755 index 0000000..9a6635a --- /dev/null +++ b/run-docker-build.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env sh + +# Author: Sven Vogel +# Created: 17.05.2024 +# Description: Builds the Dockerfile for SDK and DEVKIT + +echo "+--------------------------------------+" +echo "| CHECKING prelude |" +echo "+--------------------------------------+" + +source ./.env + +if [ -z "$SDK" ]; then + echo "no SDK specified" + exit 1 +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 -it servostar/gemstone:devkit-"$SDK" sh run-check-test.sh +if [ ! $? -eq 0 ]; then + echo "===> failed to build devkit" + exit 1 +fi + +echo "+--------------------------------------+" +echo "| DONE |" +echo "+--------------------------------------+" diff --git a/sdk/Dockerfile b/sdk/Dockerfile index aae7438..fe3592b 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 zlib zlib-dev curl-dev # create user for build RUN adduser --disabled-password lorang diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b5c1111..d3447bd 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(klib) \ No newline at end of file diff --git a/tests/klib/CMakeLists.txt b/tests/klib/CMakeLists.txt new file mode 100644 index 0000000..7542f70 --- /dev/null +++ b/tests/klib/CMakeLists.txt @@ -0,0 +1,20 @@ +include(CTest) + +include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/dep) +include_directories(${PROJECT_SOURCE_DIR}/src) + +# ------------------------------------------------------- # +# CTEST 1 +# test build configuration and dependency of Klib + +add_executable(klib_hashmap + hashmap.c) +set_target_properties(klib_hashmap + PROPERTIES + OUTPUT_NAME "klib_hashmap" + RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/klib) +target_link_libraries(klib_hashmap klib) +target_compile_options(klib_hashmap PUBLIC -Wall -Wextra -Wpedantic -Werror) + add_test(NAME klib_hashmap + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND ${GEMSTONE_BINARY_DIR}/tests/klib/klib_hashmap) diff --git a/tests/klib/hashmap.c b/tests/klib/hashmap.c new file mode 100644 index 0000000..abd7ab0 --- /dev/null +++ b/tests/klib/hashmap.c @@ -0,0 +1,36 @@ + +#include + +struct Book { + const char* author; + size_t pages; +}; + +KHASH_MAP_INIT_STR(books, struct Book) + +void put(const char* key, const struct Book book, khash_t(books)* books) { + khint_t idx; + int ret; + + idx = kh_put(books, books, key, &ret); + + if (!ret) + kh_del(books, books, idx); + + kh_value(books, idx) = book; +} + +int main(void) { + + khash_t(books) *map = kh_init(books); + + struct Book book; + book.author = "Bob"; + book.pages = 45; + + put("Pharao of Egypt", book, map); + + kh_destroy(books, map); + + return 0; +} From 47edaea82bd0bbd3c112bf81c0d44bc601c1d3ec Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 17 May 2024 15:41:52 +0200 Subject: [PATCH 02/14] sourcing .env file in action --- .github/workflows/build-check-sdk.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-check-sdk.yaml b/.github/workflows/build-check-sdk.yaml index e7a9561..91525a3 100644 --- a/.github/workflows/build-check-sdk.yaml +++ b/.github/workflows/build-check-sdk.yaml @@ -6,6 +6,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Setup environment + run: source ./.env - name: Setup SDK run: docker pull servostar/gemstone:sdk-"$SDK" - name: Compile From 24dbfc7b20a4b1a67873064371cff57c870c48bf Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 17 May 2024 15:45:34 +0200 Subject: [PATCH 03/14] sourcing env file in same shell --- .github/workflows/build-check-sdk.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-check-sdk.yaml b/.github/workflows/build-check-sdk.yaml index 91525a3..841c8a3 100644 --- a/.github/workflows/build-check-sdk.yaml +++ b/.github/workflows/build-check-sdk.yaml @@ -6,9 +6,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup environment - run: source ./.env - name: Setup SDK - run: docker pull servostar/gemstone:sdk-"$SDK" + run: source ./.env && docker pull servostar/gemstone:sdk-"$SDK" - name: Compile - run: run-check-test.sh + run: source ./.env && run-check-test.sh From 0bfd54dfb08d59ce05cfe46e2a7316c8cc058691 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 17 May 2024 15:46:35 +0200 Subject: [PATCH 04/14] calling run-docker-build.sh --- .github/workflows/build-check-sdk.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-check-sdk.yaml b/.github/workflows/build-check-sdk.yaml index 841c8a3..24118f8 100644 --- a/.github/workflows/build-check-sdk.yaml +++ b/.github/workflows/build-check-sdk.yaml @@ -9,4 +9,4 @@ jobs: - name: Setup SDK run: source ./.env && docker pull servostar/gemstone:sdk-"$SDK" - name: Compile - run: source ./.env && run-check-test.sh + run: source ./.env && run-docker-build.sh From 2ad8d8334123ae28076e3f7493714c5b54dc20e1 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 17 May 2024 15:47:25 +0200 Subject: [PATCH 05/14] calling script in shell --- .github/workflows/build-check-sdk.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-check-sdk.yaml b/.github/workflows/build-check-sdk.yaml index 24118f8..d63c874 100644 --- a/.github/workflows/build-check-sdk.yaml +++ b/.github/workflows/build-check-sdk.yaml @@ -9,4 +9,4 @@ jobs: - name: Setup SDK run: source ./.env && docker pull servostar/gemstone:sdk-"$SDK" - name: Compile - run: source ./.env && run-docker-build.sh + run: source ./.env && sh run-docker-build.sh From fa7e5d468811ffe02b475a0024409c6dff6a6dc4 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 17 May 2024 15:49:10 +0200 Subject: [PATCH 06/14] added missing files to devkit --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 0693935..cf32591 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,5 +9,7 @@ COPY --chown=lorang dep /home/lorang/dep 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 /home/lorang/ RUN cmake . From 54682b4a395334aac8cb0dd6749a8f037263898d Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 17 May 2024 15:53:27 +0200 Subject: [PATCH 07/14] made command source optional --- run-docker-build.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/run-docker-build.sh b/run-docker-build.sh index 9a6635a..2ad358a 100755 --- a/run-docker-build.sh +++ b/run-docker-build.sh @@ -8,7 +8,10 @@ echo "+--------------------------------------+" echo "| CHECKING prelude |" echo "+--------------------------------------+" -source ./.env +if [ -z "$SDK" ]; then + echo "no SDK specified, sourcing .env" + source ./.env +fi if [ -z "$SDK" ]; then echo "no SDK specified" From 00eab344ecf4734bc5de886cbf861883edc5553f Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 17 May 2024 16:02:40 +0200 Subject: [PATCH 08/14] fixed some errors --- .github/workflows/build-check-sdk.yaml | 2 +- Dockerfile | 2 +- run-docker-build.sh | 13 +++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-check-sdk.yaml b/.github/workflows/build-check-sdk.yaml index d63c874..586e0dd 100644 --- a/.github/workflows/build-check-sdk.yaml +++ b/.github/workflows/build-check-sdk.yaml @@ -9,4 +9,4 @@ jobs: - name: Setup SDK run: source ./.env && docker pull servostar/gemstone:sdk-"$SDK" - name: Compile - run: source ./.env && sh run-docker-build.sh + run: set -a && source ./.env && sh run-docker-build.sh diff --git a/Dockerfile b/Dockerfile index cf32591..dd774f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,6 @@ 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 /home/lorang/ +COPY --chown=lorang run-docker-build.sh /home/lorang/ RUN cmake . diff --git a/run-docker-build.sh b/run-docker-build.sh index 2ad358a..2d6f99f 100755 --- a/run-docker-build.sh +++ b/run-docker-build.sh @@ -11,11 +11,16 @@ echo "+--------------------------------------+" if [ -z "$SDK" ]; then echo "no SDK specified, sourcing .env" source ./.env -fi -if [ -z "$SDK" ]; then - echo "no SDK specified" - exit 1 + if [ -z "$SDK" ]; then + echo "no SDK specified" + exit 1 + else + echo "using SDK $SDK" + fi + +else + echo "using SDK $SDK" fi echo "+--------------------------------------+" From 13c176322797afab4481c64f0136c6786cf74b24 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 17 May 2024 16:16:16 +0200 Subject: [PATCH 09/14] removed klib --- dep/klib | 1 - 1 file changed, 1 deletion(-) delete mode 160000 dep/klib diff --git a/dep/klib b/dep/klib deleted file mode 160000 index 4988b65..0000000 --- a/dep/klib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4988b65b9c90473d155268c8ee15f3aad546406b From df63cffba47f71b70c7e9176bbe1d0b566ccd58a Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 17 May 2024 16:17:04 +0200 Subject: [PATCH 10/14] added submodule klib --- .gitmodules | 3 +++ dep/klib | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 dep/klib diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..48d9717 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dep/klib"] + path = dep/klib + url = https://github.com/attractivechaos/klib.git diff --git a/dep/klib b/dep/klib new file mode 160000 index 0000000..4988b65 --- /dev/null +++ b/dep/klib @@ -0,0 +1 @@ +Subproject commit 4988b65b9c90473d155268c8ee15f3aad546406b From 330ffc3b2ff0c7a6992c3827a3e30da7ae090f37 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 17 May 2024 16:50:04 +0200 Subject: [PATCH 11/14] initialized git submodule --- .github/workflows/build-check-sdk.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-check-sdk.yaml b/.github/workflows/build-check-sdk.yaml index 586e0dd..d71dcf8 100644 --- a/.github/workflows/build-check-sdk.yaml +++ b/.github/workflows/build-check-sdk.yaml @@ -6,7 +6,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Setup repository + run: git submodule init && git submodule update - name: Setup SDK - run: source ./.env && docker pull servostar/gemstone:sdk-"$SDK" + run: source ./.env && docker pull servostar/gemstone:sdk-"$SDK" - name: Compile run: set -a && source ./.env && sh run-docker-build.sh From 858a6a3c4e304bea365d461e7052a8d09cf51727 Mon Sep 17 00:00:00 2001 From: servostar Date: Sat, 18 May 2024 12:25:13 +0200 Subject: [PATCH 12/14] transioned to glib --- .gitmodules | 3 --- CMakeLists.txt | 21 +++++++-------------- Dockerfile | 1 - dep/klib | 1 - run-check-test.sh | 2 ++ sdk/Dockerfile | 2 +- tests/CMakeLists.txt | 2 +- tests/glib/CMakeLists.txt | 22 ++++++++++++++++++++++ tests/glib/glib_hashmap.c | 27 +++++++++++++++++++++++++++ tests/klib/CMakeLists.txt | 20 -------------------- tests/klib/hashmap.c | 36 ------------------------------------ 11 files changed, 60 insertions(+), 77 deletions(-) delete mode 100644 .gitmodules delete mode 160000 dep/klib create mode 100644 tests/glib/CMakeLists.txt create mode 100644 tests/glib/glib_hashmap.c delete mode 100644 tests/klib/CMakeLists.txt delete mode 100644 tests/klib/hashmap.c diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 48d9717..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "dep/klib"] - path = dep/klib - url = https://github.com/attractivechaos/klib.git diff --git a/CMakeLists.txt b/CMakeLists.txt index a0cbd38..b304447 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,25 +71,18 @@ add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE} VERBATIM) # ------------------------------------------------ # -# Klib # +# Setup Glib 2.0 # # ------------------------------------------------ # -file(GLOB KLIB_SOURCE_FILES ${PROJECT_SOURCE_DIR}/dep/klib/*.c) - -add_library(klib - STATIC - ${KLIB_SOURCE_FILES}) - -set_target_properties(klib - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/dep) +find_package(PkgConfig REQUIRED) +pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0) # ------------------------------------------------ # # Source # # ------------------------------------------------ # include_directories(${PROJECT_SOURCE_DIR}/src) -include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/dep) +include_directories(PRIVATE ${GLIB_INCLUDE_DIRS}) file(GLOB_RECURSE SOURCE_FILES src/*.c) @@ -114,7 +107,7 @@ set_target_properties(release OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/release) -target_link_libraries(release klib) +target_link_libraries(release PkgConfig::GLIB) # FIXME: cannot compile with /O2 because of /RTC1 flag if (MSVC) @@ -148,7 +141,7 @@ set_target_properties(debug OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/debug) -target_link_libraries(debug klib) +target_link_libraries(debug PkgConfig::GLIB) if (MSVC) set(DEBUG_FLAGS /DEBUG) @@ -179,7 +172,7 @@ set_target_properties(check OUTPUT_NAME "gsc" RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/check) -target_link_libraries(check klib) +target_link_libraries(check PkgConfig::GLIB) if (MSVC) set(CHECK_FLAGS /DEBUG /WX) diff --git a/Dockerfile b/Dockerfile index dd774f4..68265d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,6 @@ LABEL description="docker image for setting up the build pipeline on SDK" LABEL website="https://github.com/Servostar/gemstone" COPY --chown=lorang src /home/lorang/src -COPY --chown=lorang dep /home/lorang/dep COPY --chown=lorang tests /home/lorang/tests COPY --chown=lorang CMakeLists.txt /home/lorang/ COPY --chown=lorang run-check-test.sh /home/lorang/ diff --git a/dep/klib b/dep/klib deleted file mode 160000 index 4988b65..0000000 --- a/dep/klib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4988b65b9c90473d155268c8ee15f3aad546406b 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/sdk/Dockerfile b/sdk/Dockerfile index fe3592b..b5523b3 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 zlib zlib-dev curl-dev +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 d3447bd..1228d2b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,4 +9,4 @@ set(CTEST_BINARY_DIRECTORY ${PROJECT_BINARY_DIR}/tests) add_subdirectory(logging) add_subdirectory(input_file) add_subdirectory(ast) -add_subdirectory(klib) \ No newline at end of file +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..70c1e01 --- /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; +} diff --git a/tests/klib/CMakeLists.txt b/tests/klib/CMakeLists.txt deleted file mode 100644 index 7542f70..0000000 --- a/tests/klib/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -include(CTest) - -include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/dep) -include_directories(${PROJECT_SOURCE_DIR}/src) - -# ------------------------------------------------------- # -# CTEST 1 -# test build configuration and dependency of Klib - -add_executable(klib_hashmap - hashmap.c) -set_target_properties(klib_hashmap - PROPERTIES - OUTPUT_NAME "klib_hashmap" - RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/klib) -target_link_libraries(klib_hashmap klib) -target_compile_options(klib_hashmap PUBLIC -Wall -Wextra -Wpedantic -Werror) - add_test(NAME klib_hashmap - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - COMMAND ${GEMSTONE_BINARY_DIR}/tests/klib/klib_hashmap) diff --git a/tests/klib/hashmap.c b/tests/klib/hashmap.c deleted file mode 100644 index abd7ab0..0000000 --- a/tests/klib/hashmap.c +++ /dev/null @@ -1,36 +0,0 @@ - -#include - -struct Book { - const char* author; - size_t pages; -}; - -KHASH_MAP_INIT_STR(books, struct Book) - -void put(const char* key, const struct Book book, khash_t(books)* books) { - khint_t idx; - int ret; - - idx = kh_put(books, books, key, &ret); - - if (!ret) - kh_del(books, books, idx); - - kh_value(books, idx) = book; -} - -int main(void) { - - khash_t(books) *map = kh_init(books); - - struct Book book; - book.author = "Bob"; - book.pages = 45; - - put("Pharao of Egypt", book, map); - - kh_destroy(books, map); - - return 0; -} From 8894c6f8423a8b9e5b3c0e1e9f3dad3f6ba1acc4 Mon Sep 17 00:00:00 2001 From: servostar Date: Sat, 18 May 2024 12:52:00 +0200 Subject: [PATCH 13/14] fixed docker builld script --- run-docker-build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run-docker-build.sh b/run-docker-build.sh index 2d6f99f..aaec9c6 100755 --- a/run-docker-build.sh +++ b/run-docker-build.sh @@ -47,9 +47,9 @@ echo "+--------------------------------------+" echo "| RUNNING check test |" echo "+--------------------------------------+" -docker run -it servostar/gemstone:devkit-"$SDK" sh run-check-test.sh +docker run servostar/gemstone:devkit-"$SDK" sh run-check-test.sh if [ ! $? -eq 0 ]; then - echo "===> failed to build devkit" + echo "===> failed to run build or checks" exit 1 fi From e4334216264e06da26b89b639356108e930d012b Mon Sep 17 00:00:00 2001 From: servostar Date: Sat, 18 May 2024 14:05:12 +0200 Subject: [PATCH 14/14] fixed hashtable --- tests/glib/glib_hashmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/glib/glib_hashmap.c b/tests/glib/glib_hashmap.c index 70c1e01..116df77 100644 --- a/tests/glib/glib_hashmap.c +++ b/tests/glib/glib_hashmap.c @@ -10,7 +10,7 @@ int main(int argc, char* argv[]) { *index = i; - g_hash_table_insert(map, argv[i], &index); + g_hash_table_insert(map, argv[i], index); } for (int i = 0; i < argc; i++) {