Merge remote-tracking branch 'origin/main' into 85-implement-llvm-backend

This commit is contained in:
Sven Vogel 2024-05-20 22:10:11 +02:00
commit b6a5ee0ad6
10 changed files with 141 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,14 @@
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 repository
run: git submodule init && git submodule update
- name: Setup SDK - 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 - name: Compile
run: docker run gemstone:devkit-"$SDK" sh run-check-test.sh run: set -a && source ./.env && sh run-docker-build.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,6 +70,13 @@ add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE}
COMMENT "generate C source file for parser" COMMENT "generate C source file for parser"
VERBATIM) VERBATIM)
# ------------------------------------------------ #
# Setup Glib 2.0 #
# ------------------------------------------------ #
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
# ------------------------------------------------ # # ------------------------------------------------ #
# LLVM backend # # LLVM backend #
# ------------------------------------------------ # # ------------------------------------------------ #
@ -84,13 +93,16 @@ link_libraries(${LLVM_LIBS})
# Source # # Source #
# ------------------------------------------------ # # ------------------------------------------------ #
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(PRIVATE ${GLIB_INCLUDE_DIRS})
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()
# ------------------------------------------------ # # ------------------------------------------------ #
@ -107,6 +119,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 PkgConfig::GLIB)
# 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)
@ -139,6 +153,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 PkgConfig::GLIB)
if (MSVC) if (MSVC)
set(DEBUG_FLAGS /DEBUG) set(DEBUG_FLAGS /DEBUG)
else() else()
@ -168,6 +184,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 PkgConfig::GLIB)
if (MSVC) if (MSVC)
set(CHECK_FLAGS /DEBUG /WX) set(CHECK_FLAGS /DEBUG /WX)
else() else()

View File

@ -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 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"
@ -8,5 +8,7 @@ COPY --chown=lorang src /home/lorang/src
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/
COPY --chown=lorang .env /home/lorang/
COPY --chown=lorang run-docker-build.sh /home/lorang/
RUN cmake . RUN cmake .

View File

@ -9,6 +9,8 @@ echo "+--------------------------------------+"
echo "| BUILDING all TARGETS |" echo "| BUILDING all TARGETS |"
echo "+--------------------------------------+" echo "+--------------------------------------+"
cmake .
make -B make -B
if [ ! $? -eq 0 ]; then if [ ! $? -eq 0 ]; then
echo "===> failed to build targets" echo "===> failed to build targets"

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

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

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 glib glib-dev
# create user for build # create user for build
RUN adduser --disabled-password lorang RUN adduser --disabled-password lorang

View File

@ -9,3 +9,4 @@ 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(glib)

22
tests/glib/CMakeLists.txt Normal file
View File

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

27
tests/glib/glib_hashmap.c Normal file
View File

@ -0,0 +1,27 @@
#include <glib.h>
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;
}