Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4b13cea
feat: (wip) ArcscriptTranspiler initial cmake project
dermitzos Jun 24, 2025
ab8c007
fix: cpp transpiler library
dermitzos Jun 25, 2025
fba09d5
fix: refactor header includes
dermitzos Jun 26, 2025
4d1efc2
(cpp) fix: library outputs
dermitzos Jul 1, 2025
7aac76b
(cpp) fix: strdup imports
dermitzos Jul 1, 2025
b2a15d6
(cpp) fix: mac build
dermitzos Jul 1, 2025
3295ff1
(cpp) fix: transpiler expression evaluation & tests
dermitzos Jul 4, 2025
d437bfd
(cpp) fix: CMakeLists.txt for mac
dermitzos Jul 4, 2025
97abd94
(cpp) fix: include paths
dermitzos Jul 7, 2025
c739d2a
fix: generate folder
dermitzos Jan 24, 2026
1064981
feat: github CI for CPP
dermitzos Jan 24, 2026
92bdb92
fix: github CI for cpp
dermitzos Jan 24, 2026
5a2dd9a
chore: print cmake version
dermitzos Jan 26, 2026
d7ee53f
fix: setup cmake 3
dermitzos Jan 26, 2026
81c3fa3
fix: mac tests
dermitzos Jan 26, 2026
2dff8c8
chore: typo
dermitzos Jan 26, 2026
52c5b47
fix: test runs
dermitzos Jan 26, 2026
e897fd4
fix: arcscript single test
dermitzos Jan 26, 2026
357f0e8
fix: use specific antlr4 commit
dermitzos Jan 26, 2026
772afb7
fix: windows runner
dermitzos Jan 26, 2026
9c4541a
fix: test runs dont fail
dermitzos Jan 26, 2026
8be5615
fix: windows demo directory
dermitzos Jan 26, 2026
b381ec4
fix: demo dir again
dermitzos Jan 26, 2026
ee38bec
chore: use cache for antlr4 runtime
dermitzos Jan 26, 2026
e28ddfc
chore: use actions/cache@v5
dermitzos Jan 26, 2026
4aff241
fix: github cache save/restore
dermitzos Jan 26, 2026
9eb5706
chore: use cache primary key on save
dermitzos Jan 26, 2026
d86aa5d
chore: remove actions/cache
dermitzos Jan 26, 2026
f4b812e
fix: c++ warnings
dermitzos Jan 26, 2026
c715f3d
fix: strdup windows warning
dermitzos Jan 26, 2026
63bef67
chore: update readme
dermitzos Jan 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/cpp-build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Cpp Build and Test

on:
push:
branches: [main]
paths:
- "Cpp/**"
- "grammar/*.g4"
pull_request:
branches: [main]
paths:
- "Cpp/**"
- "grammar/*.g4"

jobs:
build-and-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest]
fail-fast: false
env:
DEMO_DIR: demo/${{ matrix.os == 'windows-latest' && 'Win32/Debug' || 'Mac' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: "3.x"

- name: Generate ANTLR4 files (Windows)
if: matrix.os == 'windows-latest'
run: .\generate.ps1

- name: Generate ANTLR4 files (macOS)
if: matrix.os == 'macos-latest'
run: sh ./generate.sh
shell: bash

- name: Configure CMake
run: |
mkdir -p Cpp/build
cd Cpp/build
cmake .. -DWITH_TEST=true

- name: Build
run: |
cd Cpp/build
cmake --build .

- name: Run tests
run: |
cd Cpp/build/${{ env.DEMO_DIR }}
ls
./ArcscriptTest
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.DS_Store

.idea
/grammar/**/.antlr
!/grammar/*.g4

Expand Down
8 changes: 7 additions & 1 deletion Cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
src/Generated
src/Generated
.idea
build
cmake-build-debug-visual-studio
cmake-build-debug
cmake-build-release-visual-studio
cmake-build-release
175 changes: 175 additions & 0 deletions Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# minimum required CMAKE version
CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)

message(STATUS "CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMake version: ${CMAKE_VERSION}")

set(PROJECT_VERSION "0.1.0")
project(ArcscriptTranspiler VERSION ${PROJECT_VERSION})

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

message(STATUS "Generator: ${CMAKE_GENERATOR}")
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_CONFIGURATION_TYPES: ${CMAKE_CONFIGURATION_TYPES}")

# compiler must be 17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# required if linking to static library
#add_definitions(-DANTLR4CPP_STATIC)

# using /MD flag for antlr4_runtime (for Visual C++ compilers only)
set(ANTLR4_WITH_STATIC_CRT OFF)

# Specify the version of the antlr4 library needed for this project.
# By default the latest version of antlr4 will be used. You can specify a
# specific, stable version by setting a repository tag value or a link
# to a zip file containing the libary source.
set(ANTLR4_TAG 8e6fd91)
# set(ANTLR4_ZIP_REPOSITORY https://github.com/antlr/antlr4/archive/refs/tags/4.13.2.zip)

# add external build for antlrcpp
include(ExternalAntlr4Cpp)
# add antlr4cpp artifacts to project environment
include_directories(${ANTLR4_INCLUDE_DIRS})

include_directories(src/Generated/ArcscriptLexer)
include_directories(src/Generated/ArcscriptParser)
include_directories(src)

add_library(ArcscriptTranspiler SHARED)

target_sources(ArcscriptTranspiler PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptTranspiler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptParserBase.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptVisitor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptOutputs.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptFunctions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptExpression.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptErrorListener.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Generated/ArcscriptLexer/ArcscriptLexer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Generated/ArcscriptParser/ArcscriptParser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Generated/ArcscriptParser/ArcscriptParserBaseVisitor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Generated/ArcscriptParser/ArcscriptParserVisitor.cpp
)

target_sources(ArcscriptTranspiler PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptTranspiler.h)

set(ARCSCRIPT_INCLUDE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptTranspiler.h
${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptHelpers.h
${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptErrorExceptions.h
${CMAKE_CURRENT_SOURCE_DIR}/src/ArcscriptOutputs.h
)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# For MSVC, we need to link against the shared library
target_compile_options(ArcscriptTranspiler PRIVATE -Wall -Wextra)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# For other compilers, we can link against the static library
target_compile_definitions(ArcscriptTranspiler PRIVATE WIN_EXPORT)
endif()

target_link_libraries(ArcscriptTranspiler PRIVATE antlr4_shared)

if (WIN32 OR WIN64)
set(LIBRARY_NAME "${PROJECT_NAME}.lib")
set(DLL_NAME "${PROJECT_NAME}.dll")
if (WIN64)
set(PLATFORM "Win64")
else()
set(PLATFORM "Win32")
endif()
elseif (APPLE)
set(DLL_NAME "lib${PROJECT_NAME}.dylib")
set(PLATFORM "Mac")
elseif (UNIX)
set(DLL_NAME "lib${PROJECT_NAME}.so")
set(PLATFORM "Linux")
endif()

set_target_properties(ArcscriptTranspiler PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib/${PLATFORM}"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib/${PLATFORM}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib/${PLATFORM}"
OUTPUT_NAME ${PROJECT_NAME}
)

if (APPLE)
add_custom_command(TARGET ArcscriptTranspiler PRE_BUILD
COMMAND install_name_tool -id @rpath/libantlr4-runtime.dylib ${ANTLR4_RUNTIME_LIBRARIES})
endif ()

# Copy the antlr4 runtime library to the output directory
add_custom_command(TARGET ArcscriptTranspiler PRE_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy ${ANTLR4_RUNTIME_LIBRARIES} "$<TARGET_FILE_DIR:ArcscriptTranspiler>"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

# Copy the generated headers to the output directory
if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/lib/include")
add_custom_command(TARGET ArcscriptTranspiler POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E make_directory "${CMAKE_CURRENT_BINARY_DIR}/lib/include")
endif()

add_custom_command(TARGET ArcscriptTranspiler POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy ${ARCSCRIPT_INCLUDE_HEADERS} "${CMAKE_CURRENT_BINARY_DIR}/lib/include"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

if (WITH_TEST)
add_executable(ArcscriptTest ${CMAKE_CURRENT_SOURCE_DIR}/demo/ArcscriptTest.cpp)

include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz)
FetchContent_MakeAvailable(json)

target_link_libraries(ArcscriptTest PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(ArcscriptTest PRIVATE ArcscriptTranspiler)

set_target_properties(ArcscriptTest PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/demo/${PLATFORM}"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/demo/${PLATFORM}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/demo/${PLATFORM}"
OUTPUT_NAME ArcscriptTest
)

file(GLOB TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/demo/tests/*.json")

if (NOT EXISTS "$<TARGET_FILE_DIR:ArcscriptTest>/tests")
add_custom_command(TARGET ArcscriptTest POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E make_directory "$<TARGET_FILE_DIR:ArcscriptTest>/tests")
endif()

add_custom_command(TARGET ArcscriptTest POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy ${TEST_SOURCES} "$<TARGET_FILE_DIR:ArcscriptTest>/tests"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

if (WIN32 OR WIN64)
set(ARCSCRIPT_TRANSPILER_LIB_FILES
"$<TARGET_FILE_DIR:ArcscriptTranspiler>/${DLL_NAME}"
"$<TARGET_FILE_DIR:ArcscriptTranspiler>/${LIBRARY_NAME}"
"$<TARGET_FILE_DIR:ArcscriptTranspiler>/${PROJECT_NAME}.exp"
"$<TARGET_FILE_DIR:ArcscriptTranspiler>/${PROJECT_NAME}.pdb"
)
elseif (APPLE)
set(ARCSCRIPT_TRANSPILER_LIB_FILES
"$<TARGET_FILE_DIR:ArcscriptTranspiler>/${DLL_NAME}"
"$<TARGET_FILE_DIR:ArcscriptTranspiler>/${LIBRARY_NAME}"
)
endif()

add_custom_command(TARGET ArcscriptTest POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy ${ANTLR4_RUNTIME_LIBRARIES} "$<TARGET_FILE_DIR:ArcscriptTest>"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

add_custom_command(TARGET ArcscriptTest POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy ${ARCSCRIPT_TRANSPILER_LIB_FILES} "$<TARGET_FILE_DIR:ArcscriptTest>"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif (WITH_TEST)
20 changes: 20 additions & 0 deletions Cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Arcscript C++ Transpiler

## Prerequisites

- CMake 3.10 or higher
- A C++ compiler that supports C++17 or higher

## Building the Project

### Windows & Linux

1. After generating the ANTLR4 parser files from the top root folder of this repository, run the following commands to build the project:

```bash
mkdir build
cd build
cmake ..
cmake --build .
```
2. The generated libraries will be located in the `build/Debug` or `build/Release` directory, depending on your build configuration. The folder also includes the `include` directory with the header files needed to use the transpiler.
Loading