mirror of
https://github.com/ArthurSonzogni/Diagon.git
synced 2026-08-29 08:34:44 +08:00
Automate production of packages.
This commit is contained in:
@@ -1,92 +1,219 @@
|
||||
name: Build and run tests
|
||||
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
create:
|
||||
tags:
|
||||
-v*
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ${{ matrix.config.name }}
|
||||
runs-on: ${{ matrix.config.os }}
|
||||
test:
|
||||
name: "Tests"
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
#- name: "Windows Latest - MSVC"
|
||||
#os: windows-latest
|
||||
#cc: "cl"
|
||||
#cxx: "cl"
|
||||
- name: "Ubuntu Latest - GCC"
|
||||
include:
|
||||
- name: "Linux GCC"
|
||||
os: ubuntu-latest
|
||||
cc: "gcc"
|
||||
cxx: "g++"
|
||||
cmake: "cmake"
|
||||
cc: gcc
|
||||
cxx: g++
|
||||
test: true
|
||||
cmake: cmake
|
||||
|
||||
- name: "Ubuntu Latest - Clang"
|
||||
- name: "Linux Clang"
|
||||
os: ubuntu-latest
|
||||
cc: "clang"
|
||||
cxx: "clang++"
|
||||
cmake: "cmake"
|
||||
cc: clang
|
||||
cxx: clang++
|
||||
test: true
|
||||
cmake: cmake
|
||||
|
||||
- name: "Ubuntu Latest - Emscripten"
|
||||
- name: "Linux emscripten"
|
||||
os: ubuntu-latest
|
||||
cc: "emcc"
|
||||
cc: emcc
|
||||
cxx: "em++"
|
||||
test: false
|
||||
cmake: "emcmake cmake"
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: seanmiddleditch/gha-setup-ninja@master
|
||||
|
||||
- name: Set Windows ENV
|
||||
if: runner.os == 'Windows'
|
||||
#- name: "MacOS clang"
|
||||
#os: macos-latest
|
||||
#cc: clang
|
||||
#cxx: clang++
|
||||
#test: true
|
||||
#cmake: cmake
|
||||
|
||||
#- name: "Windows MSVC"
|
||||
#os: windows-latest
|
||||
#cc: cl
|
||||
#cxx: cl
|
||||
#test: false
|
||||
#cmake: cmake
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: "Enable MSVC command prompt"
|
||||
if: matrix.os == 'windows-latest'
|
||||
uses: ilammy/msvc-dev-cmd@v1
|
||||
|
||||
- name: Install boost for windows
|
||||
- name: "Install cmake"
|
||||
uses: lukka/get-cmake@latest
|
||||
|
||||
- name: "Install Linux Dependencies"
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt install libboost-graph-dev uuid-dev
|
||||
|
||||
- name: "Install boost for windows"
|
||||
if: runner.os == 'Windows'
|
||||
uses: MarkusJx/install-boost@v1.0.1
|
||||
with:
|
||||
boost_version: 1.73.0
|
||||
|
||||
- name: Setup Emscripten
|
||||
if: ${{ matrix.config.cc == 'emcc' }}
|
||||
- name: "Install boost for macOS"
|
||||
if: runner.os == 'macOS'
|
||||
run: brew install boost
|
||||
|
||||
- name: "Setup Emscripten"
|
||||
if: ${{ matrix.cc == 'emcc' }}
|
||||
uses: mymindstorm/setup-emsdk@v7
|
||||
|
||||
- name: Install Linux Dependencies
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt install libboost-graph-dev
|
||||
|
||||
- name: Build
|
||||
- name: "Build debug mode"
|
||||
run: >
|
||||
mkdir build;
|
||||
cd build;
|
||||
${{ matrix.config.cmake }}
|
||||
..
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_C_COMPILER=${{ matrix.config.cc }}
|
||||
-DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }};
|
||||
${{ matrix.cmake }} ..
|
||||
-DCMAKE_BUILD_TYPE=Debug
|
||||
-DCMAKE_C_COMPILER=${{ matrix.cc }}
|
||||
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }};
|
||||
cmake --build . --config Release
|
||||
|
||||
- name: Tests
|
||||
if: ${{ matrix.config.cc != 'emcc' }}
|
||||
- name: "Run tests"
|
||||
if: matrix.test
|
||||
run: >
|
||||
cd build;
|
||||
./input_output_test
|
||||
|
||||
- name: Make webAssembly distribution
|
||||
if: ${{ matrix.config.cc == 'emcc' }}
|
||||
# Create a release on new v* tags
|
||||
release:
|
||||
needs: test
|
||||
if: ${{ github.event_name == 'create' && startsWith(github.ref, 'refs/tags/v') }}
|
||||
name: "Create release"
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
steps:
|
||||
- name: "Create release"
|
||||
uses: softprops/action-gh-release@v1
|
||||
id: create_release
|
||||
with:
|
||||
draft: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# Build artifact for the release
|
||||
package:
|
||||
name: "Build packages"
|
||||
needs: release
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- name: "Linux Clang"
|
||||
os: ubuntu-latest
|
||||
cc: clang
|
||||
cxx: clang++
|
||||
cmake: cmake
|
||||
asset_path: build/diagon*Linux*
|
||||
|
||||
- name: "Linux emscripten"
|
||||
os: ubuntu-latest
|
||||
cc: emcc
|
||||
cxx: em++
|
||||
cmake: "emcmake cmake"
|
||||
asset_path: build/diagon-Web.zip
|
||||
|
||||
#- name: "MacOS clang"
|
||||
#os: macos-latest
|
||||
#cc: clang
|
||||
#cxx: clang++
|
||||
#test: true
|
||||
#cmake: cmake
|
||||
#asset_path: build/diagon*Darwin*
|
||||
|
||||
#- name: "Windows MSVC"
|
||||
#os: windows-latest
|
||||
#cc: cl
|
||||
#cxx: cl
|
||||
#test: false
|
||||
#cmake: cmake
|
||||
#asset_path: build/diagon*Win64*
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: "Enable MSVC command prompt"
|
||||
if: matrix.os == 'windows-latest'
|
||||
uses: ilammy/msvc-dev-cmd@v1
|
||||
|
||||
- name: "Install cmake"
|
||||
uses: lukka/get-cmake@latest
|
||||
|
||||
- name: "Install Linux Dependencies"
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt install libboost-graph-dev uuid-dev zip
|
||||
|
||||
- name: "Install boost for windows"
|
||||
if: runner.os == 'Windows'
|
||||
uses: MarkusJx/install-boost@v1.0.1
|
||||
with:
|
||||
boost_version: 1.73.0
|
||||
|
||||
- name: "Setup Emscripten"
|
||||
if: ${{ matrix.cc == 'emcc' }}
|
||||
uses: mymindstorm/setup-emsdk@v7
|
||||
|
||||
- name: "Build release mode"
|
||||
run: >
|
||||
mkdir build;
|
||||
cd build;
|
||||
${{ matrix.cmake }} ..
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_C_COMPILER=${{ matrix.cc }}
|
||||
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }};
|
||||
cmake --build . --config Release;
|
||||
make package;
|
||||
|
||||
- name: "Upload native binaries"
|
||||
uses: shogo82148/actions-upload-release-asset@v1
|
||||
if: ${{ matrix.cc != 'emcc'}}
|
||||
with:
|
||||
upload_url: ${{ needs.release.outputs.upload_url }}
|
||||
asset_path: ${{ matrix.asset_path }}
|
||||
overwrite: true
|
||||
|
||||
- name: "Make webAssembly distribution"
|
||||
if: ${{ matrix.cc == 'emcc' }}
|
||||
run: >
|
||||
cd build;
|
||||
mkdir -p distribution;
|
||||
cp diagon.js distribution;
|
||||
cp diagon.wasm distribution;
|
||||
cp index.html distribution;
|
||||
cp style.css distribution;
|
||||
cp run_diagon.sh distribution;
|
||||
chmod a+x ./distribution/run_diagon.sh
|
||||
mkdir -p diagon-Web;
|
||||
cp diagon.js diagon-Web;
|
||||
cp diagon.wasm diagon-Web;
|
||||
cp index.html diagon-Web;
|
||||
cp style.css diagon-Web;
|
||||
cp run_diagon.sh diagon-Web;
|
||||
chmod a+x ./diagon-Web/run_diagon.sh;
|
||||
zip -r diagon-Web.zip diagon-Web;
|
||||
|
||||
- name: Upload WebAssembly distribution
|
||||
if: ${{ matrix.config.cc == 'emcc' }}
|
||||
uses: actions/upload-artifact@v2
|
||||
- name: "Upload WebAssembly distribution"
|
||||
if: ${{ matrix.cc == 'emcc' }}
|
||||
uses: shogo82148/actions-upload-release-asset@v1
|
||||
with:
|
||||
name: distribution
|
||||
path: build/distribution
|
||||
upload_url: ${{ needs.release.outputs.upload_url }}
|
||||
asset_path: ${{ matrix.asset_path }}
|
||||
overwrite: true
|
||||
|
||||
+51
-26
@@ -1,13 +1,31 @@
|
||||
cmake_minimum_required (VERSION 3.11)
|
||||
project(Diagon LANGUAGES C CXX)
|
||||
|
||||
set(git_version 0)
|
||||
find_package(Git)
|
||||
if (Git_FOUND)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE git_version
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
endif()
|
||||
|
||||
project(Diagon
|
||||
LANGUAGES C CXX
|
||||
VERSION ${git_version}
|
||||
)
|
||||
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_QUIET FALSE)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
FetchContent_Declare(json
|
||||
GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
|
||||
GIT_TAG v3.9.1)
|
||||
GIT_TAG v3.9.1
|
||||
GIT_PROGRESS TRUE
|
||||
)
|
||||
|
||||
FetchContent_GetProperties(json)
|
||||
if(NOT json_POPULATED)
|
||||
@@ -19,7 +37,9 @@ endif()
|
||||
|
||||
FetchContent_Declare(antlr
|
||||
GIT_REPOSITORY https://github.com/antlr/antlr4
|
||||
GIT_TAG 4.8)
|
||||
GIT_TAG 4.8
|
||||
GIT_PROGRESS TRUE
|
||||
)
|
||||
|
||||
FetchContent_GetProperties(antlr)
|
||||
if(NOT antlr_POPULATED)
|
||||
@@ -44,7 +64,10 @@ endif()
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools)
|
||||
|
||||
function(target_set_common target)
|
||||
set_property(TARGET ${target} PROPERTY CXX_STANDARD 17)
|
||||
set_target_properties(${target} PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
CXX_STANDARD 17
|
||||
)
|
||||
if (EMSCRIPTEN)
|
||||
# Nothing
|
||||
elseif (MSVC)
|
||||
@@ -71,16 +94,6 @@ set(test_directory ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
# Environment variable available in C++ source
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
execute_process(
|
||||
COMMAND
|
||||
git rev-list --count HEAD
|
||||
WORKING_DIRECTORY
|
||||
${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE
|
||||
git_version
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/environment.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/environment.h
|
||||
@@ -177,21 +190,33 @@ else()
|
||||
target_set_common(input_output_test)
|
||||
endif()
|
||||
|
||||
set(CPACK_GENERATOR "DEB")
|
||||
if (UNIX AND NOT APPLE)
|
||||
set(CPACK_GENERATOR "DEB;External;RPM;STGZ;TBZ2;TGZ;TXZ;TZ;TZST;ZIP")
|
||||
elseif (UNIX AND APPLE)
|
||||
set(CPACK_GENERATOR "DragNDrop;NuGet;TGZ;ZIP")
|
||||
elseif (WIN32)
|
||||
set(CPACK_GENERATOR "DEB;NuGet;TGZ;ZIP")
|
||||
else()
|
||||
set(CPACK_GENERATOR "ZIP")
|
||||
endif()
|
||||
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Generate beautiful ASCII art diagrams. Diagon is a collection of interactive generators. Math formulas, sequences diagrams, graph, border, ... This is written in C++, available online with WebAssembly.")
|
||||
set(CPACK_PACKAGE_HOMEPAGE_URL "https://arthursonzogni.com/Diagon/")
|
||||
set(CPACK_PACKAGE_NAME "diagon")
|
||||
set(CPACK_PACKAGE_VENDOR "Arthur Sonzogni")
|
||||
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Arthur Sonzogni")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR ${git_version})
|
||||
set(CPACK_PACKAGE_VERSION_MINOR "")
|
||||
set(CPACK_PACKAGE_VERSION_PATCH "")
|
||||
set(CPACK_DEBIAN_PACKAGE_VERSION ${git_version})
|
||||
set(CPACK_PACKAGE_HOMEPAGE_URL "https://arthursonzogni.com/Diagon/")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "
|
||||
Generate beautiful ASCII art diagrams.
|
||||
Diagon is a collection of interactive generators. Math formulas, sequences diagrams, graph,
|
||||
border, ... This is written in C++, available online with WebAssembly.
|
||||
")
|
||||
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
|
||||
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
|
||||
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
|
||||
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
|
||||
|
||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS " ")
|
||||
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://arthursonzogni.com/Diagon/")
|
||||
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE_URL "https://github.com/ArthurSonzogni/FTXUI/")
|
||||
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Arthur Sonzogni")
|
||||
set(CPACK_DEBIAN_PACKAGE_VERSION ${PROJECT_VERSION})
|
||||
|
||||
set(CPACK_RPM_PACKAGE_LICENSE MIT)
|
||||
|
||||
include(CPack)
|
||||
|
||||
@@ -9,8 +9,7 @@ else()
|
||||
set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
|
||||
FetchContent_Declare(kgt
|
||||
GIT_REPOSITORY https://github.com/ArthurSonzogni/kgt
|
||||
GIT_TAG fbf51224bee7bcf7c32bdce4fba30207d7adf862
|
||||
#GIT_TAG origin/main
|
||||
GIT_TAG c2af649438583e0ec5a97b83b5be6f1824b21a2a
|
||||
)
|
||||
FetchContent_GetProperties(kgt)
|
||||
FetchContent_Populate(kgt)
|
||||
|
||||
@@ -54,11 +54,9 @@ struct StringReader {
|
||||
using AstRulePtr = kgt::ast_rule*;
|
||||
using Opaque = void*;
|
||||
using OpaqueRead = int(Opaque);
|
||||
using InputFunction = AstRulePtr(OpaqueRead, Opaque);
|
||||
using InputFunction = AstRulePtr(OpaqueRead, Opaque, kgt::parsing_error_queue*);
|
||||
using OutputFunction = int(const struct kgt::ast_rule*);
|
||||
|
||||
InputFunction* f = kgt::abnf_input;
|
||||
|
||||
std::map<std::string, InputFunction*> input_function_map = {
|
||||
{"abnf", kgt::abnf_input}, {"bnf", kgt::bnf_input},
|
||||
{"iso-ebnf", kgt::iso_ebnf_input}, {"rbnf", kgt::rbnf_input},
|
||||
@@ -297,15 +295,26 @@ std::string Grammar::Translate(const std::string& input,
|
||||
? output_function_map[option_output]
|
||||
: kgt::rrutf8_output;
|
||||
|
||||
auto* model = input_function(StringReader::Read, &string_reader);
|
||||
int error = output_function(model);
|
||||
int error_count = 0;
|
||||
kgt::parsing_error_queue parsing_errors = NULL;
|
||||
auto* model =
|
||||
input_function(StringReader::Read, &string_reader, &parsing_errors);
|
||||
|
||||
// Restore stdout
|
||||
while (parsing_errors) {
|
||||
error_count++;
|
||||
kgt::parsing_error error;
|
||||
parsing_error_queue_pop(&parsing_errors, &error);
|
||||
std::cout << error.line << ":" << error.column << ":" << error.description
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
int error = output_function(model);
|
||||
(void)error;
|
||||
dup2(old_stdout, 1);
|
||||
close(old_stdout);
|
||||
|
||||
fclose(file_write);
|
||||
|
||||
|
||||
auto file_read = std::ifstream("/tmp/diagon_grammer.txt");
|
||||
return std::string((std::istreambuf_iterator<char>(file_read)),
|
||||
std::istreambuf_iterator<char>());
|
||||
|
||||
Reference in New Issue
Block a user