Skip to content

Commit

Permalink
Simplification pass; Back to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmdln committed Nov 1, 2023
1 parent 04cff6f commit a474686
Show file tree
Hide file tree
Showing 43 changed files with 563 additions and 766 deletions.
21 changes: 3 additions & 18 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,14 @@ Checks: |
performance-*
portability-*
readability-*
-bugprone-branch-clone
-bugprone-easily-swappable-parameters
-clang-analyzer-core.uninitialized.NewArraySize
-clang-analyzer-security.insecureAPI.decodeValueOfObjCType
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
-misc-no-recursion
-clang-analyzer-security.insecureAPI
-readability-braces-around-statements
-readability-function-cognitive-complexity
-readability-identifier-length
-readability-magic-numbers
-readability-non-const-parameter
WarningsAsErrors: |
-*
bugprone-*
cert-*-c
clang-analyzer-core
clang-analyzer-deadcode
clang-analyzer-nullability
clang-analyzer-security
clang-analyzer-unix
clang-analyzer-valist
misc-*
performance-*
portability-*
readability-*
*
-misc-no-recursion
2 changes: 1 addition & 1 deletion .clangd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
CompileFlags:
CompilationDatabase: builddir
CompilationDatabase: build

Diagnostics:
UnusedIncludes: Strict
9 changes: 7 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ indent_size = 4
indent_style = "tab"
tab_width = 4

[*.{json{,c},y{,a}ml}]
[*.json{,c}]
indent_size = 2
tab_width = 2

Expand All @@ -25,6 +25,11 @@ tab_width = 2
indent_size = 2
tab_width = 2

[meson.build]
[*.y{,a}ml]
indent_size = 2
tab_width = 2

[CMakeLists.txt]
indent_size = 4
indent_style = "tab"
tab_width = 4
47 changes: 25 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,55 @@ name: Test
on:
pull_request:
paths:
- .github/workflows/test.yml
- .clang-format
- .clang-tidy
- .clangd
- .github/workflows/test.yml
- meson.build
- include/**/*.h
- src/**/*.c
- src/**/meson.build
- CMakeLists.txt
- include/*.h
- src/*.c
- test/CMakeLists.txt
- test/*/CMakeLists.txt
push:
paths:
- .github/workflows/test.yml
- .clang-format
- .clang-tidy
- .clangd
- .github/workflows/test.yml
- meson.build
- include/**/*.h
- src/**/*.c
- src/**/meson.build
- CMakeLists.txt
- include/*.h
- src/*.c
- test/CMakeLists.txt
- test/*/CMakeLists.txt
workflow_dispatch:

jobs:
linux:
test_linux:
name: linux
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-{recommends,suggests} \
clang{,-{format,tidy}} git lld meson ninja-build \
libgc-dev libreadline-dev libasan5 libubsan1
sudo apt update && sudo apt install -y --no-install-{recommends,suggests} \
clang{,-{format,tidy}} cmake ninja-build libgc-dev libreadline-dev libasan5 libubsan1
- name: Build Ploy
env: { CC: clang, CC_LD: lld, NINJA: ninja }
env: { CC: clang, CC_LD: lld, CMAKE_GENERATOR: Ninja }
run: |
meson setup builddir -Db_sanitize=address,undefined -Dbuildtype=debugoptimized
ninja -C builddir
cmake -B build/ \
-DCMAKE_BUILD_TYPE:STRING="RelWithDebInfo"\
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \
-DPLOY_USE_ASAN:BOOL=ON
ninja -C build/
- name: Test Ploy
run: ninja -C builddir test
run: ninja -C build/ test

- name: clang-format
run: ninja -C builddir clang-format
run: ninja -C build/ clang-format

# TODO(jcmdln): Only in actions, clang-tidy warns about suppressed warnings
- name: clang-tidy
run: ninja -C builddir clang-tidy
run: ninja -C build/ clang-tidy
28 changes: 11 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,39 @@
!.editorconfig
!.gitignore
!.prettierrc.yml
!CMakeLists.txt
!LICENSE
!meson.build
!Makefile
!README.md

# Include specific files from specific directories
!.github/
!.github/workflows/
!.github/workflows/*.yml

!.vscode/
!.vscode/cmake-kits.json
!.vscode/extensions.json
!.vscode/launch.json
!.vscode/settings.json

!docs/
!docs/**/
!docs/**/*.md

!example/
!example/**/
!example/**/*.ploy
!include/
!include/**/
!include/**/*.h

!lib/
!lib/ploy/
!lib/ploy/**/
!lib/ploy/**/*.ploy

!ploy/
!ploy/**/
!ploy/**/*.ploy
!man/
!man/**

!source/
!source/**/
!source/**/*.c

!src/
!src/**/
!src/**/*.c
!test/
!test/**/
!test/**/*.[ch]

!vendor/
!vendor/**/
!vendor/**/*
3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"llvm-vs-code-extensions.vscode-clangd",
"redhat.vscode-yaml",
"vadimcn.vscode-lldb",
"ms-vscode.cmake-tools",
"mesonbuild.mesonbuild"
"ms-vscode.cmake-tools"
]
}
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
{
"type": "lldb",
"request": "launch",
"name": "Debug Ploy",
"program": "${workspaceFolder}/builddir/ploy",
"args": [],
"name": "Debug Ploy Demo",
"program": "${workspaceFolder}/build/ploy",
"args": ["-f", "${workspaceFolder}/example/demo.ploy"],
"cwd": "${workspaceFolder}"
}
]
Expand Down
14 changes: 7 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"--header-insertion=never"
],

// Don't immediately pester the user on open of the project
"cmake.configureOnOpen": false,
// Don't focusing CMake logs on changes
"cmake.revealLog": "never",
// Don't clutter the statusbar
"cmake.useProjectStatusView": true,

// Make Prettier the default formatter
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.insertSpaces": true,
Expand All @@ -22,10 +29,6 @@
"**/builddir/**": true
},

// Don't pester about or download a random binary
"mesonbuild.downloadLanguageServer": false,
"mesonbuild.languageServer": null,

// Associate YAML schemas with targets
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": [
Expand All @@ -44,8 +47,5 @@
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[meson]": {
"editor.defaultFormatter": "mesonbuild.mesonbuild"
}
}
81 changes: 81 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
cmake_minimum_required(VERSION 3.13)
project(Ploy LANGUAGES C VERSION 0.0.0)

add_executable(ploy src/main.c src/core.c src/eval.c src/math.c src/read.c)
target_compile_options(ploy PRIVATE -DPLOY_VERSION=\"${CMAKE_PROJECT_VERSION}\")
target_include_directories(ploy PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")

#
# Compilation
#

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

target_compile_features(ploy PRIVATE c_std_11)
target_compile_options(ploy PRIVATE
-fshort-wchar -fstrict-aliasing -funsigned-char
-Wall -Wextra -pedantic
-Werror=cast-qual
-Werror=conversion
-Werror=implicit-int
-Werror=strict-prototypes
-Werror=switch
-Werror=vla
-Werror=write-strings
)

option(PLOY_LTO "Build ploy with link-time optimization" OFF)
if(PLOY_LTO)
target_compile_options(ploy PRIVATE -flto)
target_link_options(ploy PRIVATE -flto)
endif()

option(PLOY_USE_ASAN "Build ploy with AddressSanitizer" OFF)
if(PLOY_USE_ASAN)
target_compile_options(ploy PRIVATE -fsanitize=address,undefined)
target_link_options(ploy PRIVATE -fsanitize=address,undefined)
endif()

option(PLOY_USE_TSAN "Build ploy with ThreadSanitizer" OFF)
if(PLOY_USE_TSAN)
target_compile_options(ploy PRIVATE -fsanitize=thread,undefined)
target_link_options(ploy PRIVATE -fsanitize=thread,undefined)
endif()

#
# Dependencies
#

find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(bdwgc REQUIRED IMPORTED_TARGET bdw-gc>=8)
pkg_check_modules(readline REQUIRED IMPORTED_TARGET readline>=8)
target_link_libraries(ploy PUBLIC PkgConfig::bdwgc PkgConfig::readline)
endif()

#
# Lints
#

add_custom_target(clang-format
COMMAND clang-format --dry-run --verbose --Werror
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.c"
)

add_custom_target(clang-tidy
COMMAND clang-tidy -p "${CMAKE_CURRENT_SOURCE_DIR}/build"
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.c"
)

#
# Tests
#

if(CMAKE_PROJECT_NAME MATCHES Ploy)
include(CTest)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/test")
endif()
Loading

0 comments on commit a474686

Please sign in to comment.