added klib as external library

This commit is contained in:
Sven Vogel 2024-05-17 15:39:07 +02:00
parent a3e3e25e18
commit 6d03b97b9c
10 changed files with 143 additions and 10 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
SDK=0.2.4-alpine-3.19.1

View File

@ -1,14 +1,12 @@
name: "Build check gemstone in SDK" name: "Build check gemstone in SDK"
run-name: SDK build check to ${{ inputs.deploy_target }} by @${{ github.actor }} run-name: SDK build check to ${{ inputs.deploy_target }} by @${{ github.actor }}
on: [push, pull_request] on: [push, pull_request]
env:
SDK: 0.2.3-alpine-3.19.1
jobs: jobs:
build-check-sdk: build-check-sdk:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup SDK - 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 - name: Compile
run: docker run gemstone:devkit-"$SDK" sh run-check-test.sh run: run-check-test.sh

View File

@ -4,6 +4,8 @@ cmake_minimum_required(VERSION 3.15...3.25)
# Header must be included this way: #include <module/header.h> # Header must be included this way: #include <module/header.h>
# #
# res # res
# dep
# klib
# src # src
# lex # lex
# lexer.l # lexer.l
@ -68,17 +70,34 @@ add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE}
COMMENT "generate C source file for parser" COMMENT "generate C source file for parser"
VERBATIM) 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 # # Source #
# ------------------------------------------------ # # ------------------------------------------------ #
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/dep)
file(GLOB_RECURSE SOURCE_FILES src/*.c) file(GLOB_RECURSE SOURCE_FILES src/*.c)
# define default compile flags # define default compile flags
if (MSVC) if (MSVC)
set(FLAGS /Wall /W3 /permissive) set(FLAGS /Wall /W3 /permissive)
else() else()
set(FLAGS -Wall -Wextra -Wconversion -Wpedantic) set(FLAGS -Wall -Wextra -Wpedantic)
endif() endif()
# ------------------------------------------------ # # ------------------------------------------------ #
@ -95,6 +114,8 @@ set_target_properties(release
OUTPUT_NAME "gsc" OUTPUT_NAME "gsc"
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/release) RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/release)
target_link_libraries(release klib)
# FIXME: cannot compile with /O2 because of /RTC1 flag # FIXME: cannot compile with /O2 because of /RTC1 flag
if (MSVC) if (MSVC)
set(RELEASE_FLAGS) set(RELEASE_FLAGS)
@ -127,6 +148,8 @@ set_target_properties(debug
OUTPUT_NAME "gsc" OUTPUT_NAME "gsc"
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/debug) RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/debug)
target_link_libraries(debug klib)
if (MSVC) if (MSVC)
set(DEBUG_FLAGS /DEBUG) set(DEBUG_FLAGS /DEBUG)
else() else()
@ -156,6 +179,8 @@ set_target_properties(check
OUTPUT_NAME "gsc" OUTPUT_NAME "gsc"
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/check) RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/check)
target_link_libraries(check klib)
if (MSVC) if (MSVC)
set(CHECK_FLAGS /DEBUG /WX) set(CHECK_FLAGS /DEBUG /WX)
else() else()

View File

@ -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 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 description="docker image for setting up the build pipeline on SDK"
LABEL website="https://github.com/Servostar/gemstone" LABEL website="https://github.com/Servostar/gemstone"
COPY --chown=lorang src /home/lorang/src COPY --chown=lorang src /home/lorang/src
COPY --chown=lorang dep /home/lorang/dep
COPY --chown=lorang tests /home/lorang/tests COPY --chown=lorang tests /home/lorang/tests
COPY --chown=lorang CMakeLists.txt /home/lorang/ COPY --chown=lorang CMakeLists.txt /home/lorang/
COPY --chown=lorang run-check-test.sh /home/lorang/ COPY --chown=lorang run-check-test.sh /home/lorang/

1
dep/klib Submodule

@ -0,0 +1 @@
Subproject commit 4988b65b9c90473d155268c8ee15f3aad546406b

50
run-docker-build.sh Executable file
View File

@ -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 "+--------------------------------------+"

View File

@ -1,11 +1,11 @@
FROM alpine:3.19.1 FROM alpine:3.19.1
LABEL authors="servostar" 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 description="base image for building the gemstone programming language compiler"
LABEL website="https://github.com/Servostar/gemstone" LABEL website="https://github.com/Servostar/gemstone"
# install dependencies # 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 # create user for build
RUN adduser --disabled-password lorang RUN adduser --disabled-password lorang

View File

@ -8,4 +8,5 @@ set(CTEST_BINARY_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
add_subdirectory(logging) add_subdirectory(logging)
add_subdirectory(input_file) add_subdirectory(input_file)
add_subdirectory(ast) add_subdirectory(ast)
add_subdirectory(klib)

20
tests/klib/CMakeLists.txt Normal file
View File

@ -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)

36
tests/klib/hashmap.c Normal file
View File

@ -0,0 +1,36 @@
#include <klib/khash.h>
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;
}