Skip to content

Commit

Permalink
Don't bundle vendor dependencies; Add Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmdln committed Oct 21, 2023
1 parent 91ef215 commit e338d67
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PointerAlignment: Right
SortIncludes: Never
SortIncludes: CaseSensitive
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
Expand Down
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ tab_width = 2
[*.ploy]
indent_size = 2
tab_width = 2

[Makefile]
indent_size = 4
indent_style = "tab"
tab_width = 4
41 changes: 17 additions & 24 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,47 +35,40 @@ jobs:
fail-fast: false
matrix:
linter:
- name: clang-format
- name: clang-tidy
- clang-format
- clang-tidy
os:
- name: ubuntu-latest
deps: clang clang-format clang-tidy cmake git libasan5 libubsan1 lld ninja-build
deps: clang{,-{format,tidy}} cmake git libasan5 libubsan1 lld ninja-build

name: ${{ matrix.linter.name }} (${{ matrix.os.name }})
name: ${{ matrix.linter }} (${{ matrix.os.name }})
runs-on: ${{ matrix.os.name }}

steps:
- uses: actions/checkout@v4
with:
submodules: true
with: { submodules: true }

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-{recommends,suggests} ${{ matrix.os.deps }}
- name: Setup build cache
uses: actions/cache@v3
id: build
with:
key: build-${{ hashFiles('**/CMakeLists.txt', '**/*.c', '**/*.h') }}
key: ${{ hashFiles('**/CMakeLists.txt', 'src/*.c', 'include/**/*.h') }}
path: build/

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-{recommends,suggests} ${{ matrix.os.deps }}
# TODO(jcmdln): Test ploy
- name: Build Ploy (Debug)
env:
CC: clang
CXX: clang++
LD: lld
env: { CC: clang, CXX: clang++, LD: lld }
run: |
[ ! -e build ] && mkdir build
cd build
cmake -G Ninja .. \
-DCMAKE_BUILD_TYPE:STRING=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE
ninja
cmake -G Ninja -B build/ -S ./ \
-DCMAKE_BUILD_TYPE:STRING="RelWithDebInfo"
ninja -C build/
# TODO(jcmdln): Only in actions, clang-tidy warns about suppressed warnings
- name: Run ${{ matrix.linter.name }}
- name: Run ${{ matrix.linter }}
run: |
ninja -C build ${{ matrix.linter.name }}
ninja -C build ${{ matrix.linter }}
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
!.prettierrc.yml
!LICENSE
!CMakeLists.txt
!Makefile
!README.md

# Include specific files from specific directories
Expand All @@ -34,9 +35,13 @@
!include/**/
!include/**/*.h

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

!man/
!man/**

!src/
!src/**/
Expand Down
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

25 changes: 16 additions & 9 deletions .vscode/cmake-kits.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,38 @@
{
"name": "Linux-Clang",
"compilers": {
"C": "/usr/bin/clang",
"CXX": "/usr/bin/clang++"
"CC": "clang",
"CC_LD": "lld",
"CXX": "clang++",
"CXX_LD": "lld",
"LD": "lld"
}
},
{
"name": "Linux-Clang-Mold",
"compilers": {
"C": "/usr/bin/clang",
"CXX": "/usr/bin/clang++",
"LD": "/usr/bin/mold"
"CC": "clang",
"CC_LD": "mold",
"CXX": "clang++",
"CXX_LD": "mold",
"LD": "mold"
}
},
{
"name": "Linux-GCC",
"compilers": {
"C": "/usr/bin/gcc",
"CC": "/usr/bin/gcc",
"CXX": "/usr/bin/g++"
}
},
{
"name": "Linux-GCC-Mold",
"compilers": {
"C": "/usr/bin/gcc",
"CXX": "/usr/bin/g++",
"LD": "/usr/bin/mold"
"CC": "gcc",
"CC_LD": "mold",
"CXX": "g++",
"CXX_LD": "mold",
"LD": "mold"
}
}
]
134 changes: 48 additions & 86 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,134 +3,96 @@
# Copyright (c) 2023 Johnathan C Maudlin <[email protected]>

cmake_minimum_required(VERSION 3.13)
project(Ploy LANGUAGES C VERSION 0.0.0)
project(Ploy LANGUAGES C VERSION 0.0.1)

add_executable(ploy
src/main.c
src/core.c
src/evaluator.c
src/main.c
src/math.c
src/printer.c
src/reader.c
src/type.c
)

target_include_directories(ploy
PUBLIC
${PROJECT_SOURCE_DIR}/include
)
target_include_directories(ploy PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")

#
# Compilation
#

target_compile_features(ploy
PRIVATE
c_std_11
)
target_compile_features(ploy PRIVATE c_std_11)

target_compile_options(ploy
PRIVATE
-flto
target_compile_options(ploy PRIVATE
-DPLOY_VERSION=\"${CMAKE_PROJECT_VERSION}\"
-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
-Wno-error=pedantic
-Wno-error=unused-but-set-parameter
-Wno-error=unused-parameter
-Wno-error=unused-result
-Wno-error=unused-variable
)

target_link_options(ploy
PRIVATE
-flto
)

if (CMAKE_C_COMPILER_ID MATCHES "Clang")
target_compile_options(ploy
PRIVATE
-Werror=ignored-qualifiers
-Werror=unreachable-code-break
-Werror=unreachable-code-return
)
elseif (CMAKE_C_COMPILER_ID MATCHES "GNU")
target_compile_options(ploy
PRIVATE
-Werror=discarded-qualifiers
-Werror=switch-unreachable
)
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()

if (CMAKE_BUILD_TYPE MATCHES "Debug")
target_compile_options(ploy
PRIVATE
-fsanitize=address
-fsanitize=undefined
)
target_link_options(ploy
PRIVATE
-fsanitize=address
-fsanitize=undefined
)
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()

if (CMAKE_C_COMPILER_ID MATCHES "Clang")
target_compile_options(ploy
PRIVATE
-fsanitize=float-divide-by-zero
-fsanitize=implicit-conversion
-fsanitize=integer
-fsanitize=nullability
)
elseif (CMAKE_C_COMPILER_ID MATCHES "GNU")
target_compile_options(ploy
PRIVATE
-fsanitize=pointer-compare
-fsanitize=pointer-subtract
)
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
#

# https://github.com/ivmai/bdwgc
# TODO(jcmdln): Find something smaller? Build my own GC?
# TODO(jcmdln): Read https://github.com/orangeduck/tgc
# TODO(jcmdln): Read https://github.com/bullno1/ugc
# TODO(jcmdln): Read https://github.com/nyuichi/gc.h
add_subdirectory(${PROJECT_SOURCE_DIR}/vendor/bdwgc)

# https://github.com/jart/bestline
add_library(bestline SHARED ${PROJECT_SOURCE_DIR}/vendor/bestline/bestline.c)
target_include_directories(bestline PUBLIC ${PROJECT_SOURCE_DIR}/vendor/bestline)

target_link_libraries(ploy
PRIVATE
bestline
gc
)
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()

#
# Ploy
#

# -DPLOY_BIN_DIR
# -DPLOY_LIB_DIR
# -DPLOY_VERSION

#
# Lints
#

add_custom_target(clang-format
COMMAND
clang-format --dry-run --verbose --Werror
${PROJECT_SOURCE_DIR}/include/**/*.h
${PROJECT_SOURCE_DIR}/src/*.c
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 ${PROJECT_SOURCE_DIR}/build
${PROJECT_SOURCE_DIR}/include/**/*.h
${PROJECT_SOURCE_DIR}/src/*.c
COMMAND clang-tidy -p "${CMAKE_CURRENT_SOURCE_DIR}/build"
"${CMAKE_CURRENT_SOURCE_DIR}/include/**/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.c"
)

#
# Tests
#
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C Maudlin <[email protected]>
.POSIX:

VERSION = 0.0.1

CC = cc
CFLAGS = -O2 -std=c11 \
-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
LDFLAGS = -D_DEFAULT_SOURCE -DPLOY_VERSION=\"$(VERSION)\" \
-Iinclude/ -lgc -lm -lreadline -pthread
PREFIX = /usr/local
SOURCES = \
src/main.c \
src/core.c \
src/evaluator.c \
src/math.c \
src/printer.c \
src/reader.c \
src/type.c

all: release

clean:
rm -f ploy

debug: $(SOURCES)
$(CC) -g -Werror $(CFLAGS) -o ploy $(SOURCES) $(LDFLAGS)
asan: $(SOURCES)
$(CC) -g -Werror -fsanitize=address,undefined $(CFLAGS) -o ploy $(SOURCES) $(LDFLAGS)
tsan: $(SOURCES)
$(CC) -g -Werror -fsanitize=thread $(CFLAGS) -o ploy $(SOURCES) $(LDFLAGS)
release: $(SOURCES)
$(CC) $(CFLAGS) -o ploy $(SOURCES) $(LDFLAGS)

# install:
#
# uninstall:
File renamed without changes.
Loading

0 comments on commit e338d67

Please sign in to comment.