Skip to content

Commit 8e3f79b

Browse files
Advance GW-BASIC compatibility and tooling
1 parent be1b5bf commit 8e3f79b

31 files changed

Lines changed: 2552 additions & 65 deletions

.clang-tidy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Checks: >
2+
clang-analyzer-*,
3+
bugprone-*,
4+
performance-*,
5+
portability-*,
6+
readability-*
7+
WarningsAsErrors: '*'
8+
HeaderFilterRegex: '.*'
9+
AnalyzeTemporaryDtors: false
10+
CheckOptions:
11+
- key: readability-identifier-length.IgnoredVariableNames
12+
value: 'i|j|x|y|ch|hr|ec|it|in|os'
13+
- key: readability-function-cognitive-complexity.Threshold
14+
value: '80'
15+
- key: readability-function-size.LineThreshold
16+
value: '250'

.github/workflows/ci.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build-and-test:
9+
name: ${{ matrix.name }} / ${{ matrix.config }}
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
include:
15+
- os: windows-latest
16+
name: Windows MSVC
17+
config: Debug
18+
cmake_args: ""
19+
- os: windows-latest
20+
name: Windows MSVC
21+
config: Release
22+
cmake_args: ""
23+
- os: ubuntu-latest
24+
name: Linux GCC
25+
config: Debug
26+
cmake_args: "-DCMAKE_CXX_COMPILER=g++"
27+
- os: ubuntu-latest
28+
name: Linux GCC
29+
config: Release
30+
cmake_args: "-DCMAKE_CXX_COMPILER=g++"
31+
- os: ubuntu-latest
32+
name: Linux Clang
33+
config: Debug
34+
cmake_args: "-DCMAKE_CXX_COMPILER=clang++"
35+
- os: ubuntu-latest
36+
name: Linux Clang
37+
config: Release
38+
cmake_args: "-DCMAKE_CXX_COMPILER=clang++"
39+
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
44+
- name: Install Linux dependencies
45+
if: runner.os == 'Linux'
46+
run: |
47+
sudo apt-get update
48+
sudo apt-get install -y clang g++ libx11-dev libgl1-mesa-dev
49+
50+
- name: Configure
51+
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.config }} ${{ matrix.cmake_args }}
52+
53+
- name: Build
54+
run: cmake --build build --config ${{ matrix.config }} --parallel
55+
56+
- name: Test
57+
run: ctest --test-dir build -C ${{ matrix.config }} --output-on-failure
58+
59+
static-analysis:
60+
name: Static analysis
61+
runs-on: ubuntu-latest
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@v4
65+
66+
- name: Install tools and dependencies
67+
run: |
68+
sudo apt-get update
69+
sudo apt-get install -y clang-tidy cppcheck libx11-dev libgl1-mesa-dev
70+
71+
- name: Configure
72+
run: >
73+
cmake -S . -B build-analysis
74+
-DCMAKE_BUILD_TYPE=Debug
75+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
76+
-DGWBASIC_ENABLE_CLANG_TIDY=ON
77+
-DGWBASIC_ENABLE_CPPCHECK=ON
78+
79+
- name: Analyze
80+
run: cmake --build build-analysis --parallel
81+
82+
fuzz-smoke:
83+
name: Fuzz smoke
84+
runs-on: ubuntu-latest
85+
steps:
86+
- name: Checkout
87+
uses: actions/checkout@v4
88+
89+
- name: Install dependencies
90+
run: |
91+
sudo apt-get update
92+
sudo apt-get install -y clang libx11-dev libgl1-mesa-dev
93+
94+
- name: Configure
95+
run: >
96+
cmake -S . -B build-fuzz
97+
-DCMAKE_CXX_COMPILER=clang++
98+
-DCMAKE_BUILD_TYPE=Debug
99+
-DGWBASIC_BUILD_TESTS=OFF
100+
-DGWBASIC_BUILD_FUZZERS=ON
101+
102+
- name: Build fuzzer
103+
run: cmake --build build-fuzz --target gwbasic_lexer_parser_fuzzer --parallel
104+
105+
- name: Run fuzzer smoke
106+
run: ./build-fuzz/gwbasic_lexer_parser_fuzzer -runs=100

.github/workflows/docs.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: pages
16+
cancel-in-progress: false
17+
18+
jobs:
19+
build-docs:
20+
name: Build API docs
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Install Doxygen
27+
run: |
28+
sudo apt-get update
29+
sudo apt-get install -y doxygen graphviz
30+
31+
- name: Configure
32+
run: cmake -S . -B build-docs -DGWBASIC_BUILD_DOCS=ON
33+
34+
- name: Build docs
35+
run: cmake --build build-docs --target docs
36+
37+
- name: Upload Pages artifact
38+
if: github.event_name == 'push'
39+
uses: actions/upload-pages-artifact@v3
40+
with:
41+
path: build-docs/docs/api/html
42+
43+
deploy:
44+
name: Deploy Pages
45+
if: github.event_name == 'push'
46+
needs: build-docs
47+
runs-on: ubuntu-latest
48+
environment:
49+
name: github-pages
50+
url: ${{ steps.deployment.outputs.page_url }}
51+
steps:
52+
- name: Deploy to GitHub Pages
53+
id: deployment
54+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ CTestTestfile.cmake
1111
_deps
1212
CMakeUserPresets.json
1313
build/
14+
.verify-cmake/
15+
.verify-tidy/
16+
.verify-tidy-vs/
1417

1518
# CLion
1619
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
1720
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
1821
# and can be added to the global gitignore or merged into this file. For a more nuclear
1922
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
20-
#cmake-build-*
23+
#cmake-build-*

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
cmake_minimum_required(VERSION 3.21)
22
project(gwbasic_modern VERSION 0.1.0 LANGUAGES CXX)
3+
include(cmake/StaticAnalysis.cmake)
4+
include(cmake/Doxygen.cmake)
35
set(CMAKE_CXX_STANDARD 20)
46
set(CMAKE_CXX_STANDARD_REQUIRED ON)
57
set(CMAKE_CXX_EXTENSIONS OFF)
68
option(GWBASIC_BUILD_TESTS "Build tests" ON)
9+
option(GWBASIC_BUILD_FUZZERS "Build libFuzzer targets" OFF)
710
add_library(gwbasic_core src/token.cpp src/lexer.cpp src/ast.cpp src/parser.cpp src/value.cpp src/runtime.cpp src/interpreter.cpp src/graphics_presenter.cpp)
811
target_include_directories(gwbasic_core PUBLIC include)
912
if(WIN32)
@@ -24,4 +27,28 @@ if(GWBASIC_BUILD_TESTS)
2427
add_executable(gwbasic_smoke tests/smoke.cpp)
2528
target_link_libraries(gwbasic_smoke PRIVATE gwbasic_core)
2629
add_test(NAME smoke COMMAND gwbasic_smoke)
30+
31+
add_executable(gwbasic_lexer_tests tests/lexer_tests.cpp)
32+
target_link_libraries(gwbasic_lexer_tests PRIVATE gwbasic_core)
33+
add_test(NAME lexer COMMAND gwbasic_lexer_tests)
34+
35+
add_executable(gwbasic_parser_tests tests/parser_tests.cpp)
36+
target_link_libraries(gwbasic_parser_tests PRIVATE gwbasic_core)
37+
add_test(NAME parser COMMAND gwbasic_parser_tests)
38+
39+
add_executable(gwbasic_compatibility_tests tests/compatibility_tests.cpp)
40+
target_link_libraries(gwbasic_compatibility_tests PRIVATE gwbasic_core)
41+
add_test(NAME compatibility COMMAND gwbasic_compatibility_tests)
42+
endif()
43+
44+
if(GWBASIC_BUILD_FUZZERS)
45+
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
46+
message(FATAL_ERROR "GWBASIC_BUILD_FUZZERS requires Clang with libFuzzer support")
47+
endif()
48+
target_compile_options(gwbasic_core PRIVATE -fsanitize=fuzzer-no-link,address,undefined)
49+
target_link_options(gwbasic_core PRIVATE -fsanitize=address,undefined)
50+
add_executable(gwbasic_lexer_parser_fuzzer tests/fuzz_lexer_parser.cpp)
51+
target_link_libraries(gwbasic_lexer_parser_fuzzer PRIVATE gwbasic_core)
52+
target_compile_options(gwbasic_lexer_parser_fuzzer PRIVATE -fsanitize=fuzzer,address,undefined)
53+
target_link_options(gwbasic_lexer_parser_fuzzer PRIVATE -fsanitize=fuzzer,address,undefined)
2754
endif()

CMakePresets.json

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 21,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "debug",
11+
"displayName": "Debug",
12+
"description": "Default debug build with tests enabled.",
13+
"binaryDir": "${sourceDir}/build/debug",
14+
"cacheVariables": {
15+
"CMAKE_BUILD_TYPE": "Debug",
16+
"GWBASIC_BUILD_TESTS": "ON"
17+
}
18+
},
19+
{
20+
"name": "release",
21+
"displayName": "Release",
22+
"description": "Optimized release build with tests enabled.",
23+
"binaryDir": "${sourceDir}/build/release",
24+
"cacheVariables": {
25+
"CMAKE_BUILD_TYPE": "Release",
26+
"GWBASIC_BUILD_TESTS": "ON"
27+
}
28+
},
29+
{
30+
"name": "analysis",
31+
"displayName": "Static Analysis",
32+
"description": "Debug build with clang-tidy and Cppcheck enabled.",
33+
"binaryDir": "${sourceDir}/build/analysis",
34+
"cacheVariables": {
35+
"CMAKE_BUILD_TYPE": "Debug",
36+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
37+
"GWBASIC_ENABLE_CLANG_TIDY": "ON",
38+
"GWBASIC_ENABLE_CPPCHECK": "ON"
39+
}
40+
},
41+
{
42+
"name": "docs",
43+
"displayName": "Documentation",
44+
"description": "Generate Doxygen API documentation.",
45+
"binaryDir": "${sourceDir}/build/docs",
46+
"cacheVariables": {
47+
"GWBASIC_BUILD_DOCS": "ON",
48+
"GWBASIC_BUILD_TESTS": "OFF"
49+
}
50+
}
51+
],
52+
"buildPresets": [
53+
{
54+
"name": "debug",
55+
"configurePreset": "debug"
56+
},
57+
{
58+
"name": "release",
59+
"configurePreset": "release"
60+
},
61+
{
62+
"name": "analysis",
63+
"configurePreset": "analysis"
64+
},
65+
{
66+
"name": "docs",
67+
"configurePreset": "docs",
68+
"targets": [
69+
"docs"
70+
]
71+
}
72+
],
73+
"testPresets": [
74+
{
75+
"name": "debug",
76+
"configurePreset": "debug",
77+
"output": {
78+
"outputOnFailure": true
79+
}
80+
},
81+
{
82+
"name": "release",
83+
"configurePreset": "release",
84+
"output": {
85+
"outputOnFailure": true
86+
}
87+
}
88+
]
89+
}

0 commit comments

Comments
 (0)