Skip to content

Swift markdown support #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 57 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
2b633c5
build: remove extra defines on Windows
compnerd Dec 20, 2023
a37e62f
build: add exports configuration for CMake
compnerd Dec 20, 2023
ade8e9d
build: install additional headers
compnerd Dec 20, 2023
66f64cb
build: split apart installed headers and install module.modulemap
compnerd Dec 20, 2023
64f62e7
build: apply upstream cmark change for python support
compnerd Dec 20, 2023
14741ba
build: adjust the cmark extensions build for vendoring
compnerd Dec 20, 2023
f4fbcd1
replace usage of CMARK_INLINE with inline
compnerd Jan 4, 2024
6083a22
remove `HAVE_UNISTD_H` in favour of compiler checks
compnerd Jan 4, 2024
34de504
build: remove `/TP` usage on MSVC
compnerd Jan 4, 2024
338dfea
remove some compiler compatibility shims
compnerd Jan 4, 2024
5692bba
remove check for `__builtin_expect`
compnerd Jan 4, 2024
706b593
build: remove some unused includes
compnerd Jan 4, 2024
a6276c4
remove some compiler compatibility shims
compnerd Jan 4, 2024
66c73c2
build: hoist the policy settings
compnerd Jan 4, 2024
651b360
build: adjust the policy to silence warnings on MSVC builds
compnerd Jan 4, 2024
58994ef
build: standardise the layout for the CMake project
compnerd Jan 4, 2024
7036901
build: centralise the CMake includes
compnerd Jan 4, 2024
3b7864b
build: improve man page installation
compnerd Jan 4, 2024
62391a3
build: centralise the application of flags
compnerd Jan 4, 2024
b9db691
build: replace CMARK_TESTS with BUILD_TESTING
compnerd Jan 4, 2024
44bb5f3
test: move api_test handling into api_tests
compnerd Jan 4, 2024
00149d3
tests: remove unnecessary "test"
compnerd Jan 4, 2024
3def51e
test: remove unused variable
compnerd Jan 4, 2024
c7bd0eb
build: correct typo and adjust command invocation
compnerd Jan 4, 2024
745073f
build: use generator expression for path computation
compnerd Jan 4, 2024
f6c40dc
build: reflow some text to match CMake documentation style
compnerd Jan 4, 2024
a3de9ed
build: hoist the C visibility settings to top level
compnerd Jan 4, 2024
edd48c3
build: uniformly specify C standard & extensions
compnerd Jan 4, 2024
c458cc2
test: add a cast to silence a MSVC warning (C4152)
compnerd Jan 4, 2024
2e5584c
build: clean up static define
compnerd Jan 4, 2024
5c14e3b
build: hoist profiling flags and debug macros up
compnerd Jan 4, 2024
32f0f77
build: protect the integrity of user variables
compnerd Jan 4, 2024
8b51fc2
build: do not intrude upon the sanctity of the user flags
compnerd Jan 4, 2024
4fe1fd6
build: only build the fuzzer when appropriate
compnerd Jan 4, 2024
5234879
glob: don't glob the headers
compnerd Jan 4, 2024
fa7f441
build: remove the use of generated export header
compnerd Jan 4, 2024
845897a
build: permit incremental linking on Windows
compnerd Jan 5, 2024
adab37d
build: prefer the GNU install dirs uniformly
compnerd Jan 5, 2024
403f409
build: rely on CMake to drive thread linkage
compnerd Jan 5, 2024
56fd134
build: remove unnecessary variables
compnerd Jan 5, 2024
bb3619e
build: use CMAKE_INCLUDE_CURRENT_DIR
compnerd Jan 5, 2024
8a5ffa0
build: prefer to use CMake to propagate include directories
compnerd Jan 5, 2024
3c4fd90
build: remove `CMARK_SHARED` and `CMARK_STATIC`
compnerd Jan 5, 2024
a6a5db4
build: remove extraneous variable definition
compnerd Jan 5, 2024
7d6b965
build: inline useless variables
compnerd Jan 5, 2024
3b3b6e8
build: bulk set target properties
compnerd Jan 5, 2024
b3a7754
build: simplify version handling
compnerd Jan 5, 2024
ebc53bf
build: remove unnecessary include path handling
compnerd Jan 5, 2024
c788cd0
build: clean up the install rules
compnerd Jan 5, 2024
aef4761
build: hoist `CMARK_THREADING` to a build-only config
compnerd Jan 5, 2024
e049736
remove `mutex.h` from the distribution
compnerd Jan 5, 2024
6f64876
remove empty `config.h` and `cmark-gfm_config.h` headers
compnerd Jan 5, 2024
8aa6779
build: remove generation of the version
compnerd Jan 5, 2024
c5d1389
build: reorganise the build files
compnerd Jan 5, 2024
33410d5
build: propagate the static define for Swift
compnerd Jan 9, 2024
ba66792
build: restore cmarkTargets.cmake for non-Windows targets
compnerd Jan 16, 2024
b59a9a3
build: `cmark-gfm.h` is not an umbrella header
compnerd Jan 18, 2024
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
121 changes: 87 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,61 +1,114 @@
cmake_minimum_required(VERSION 3.12)

if(POLICY CMP0063)
cmake_policy(SET CMP0063 NEW)
endif()

if(POLICY CMP0092)
cmake_policy(SET CMP0092 NEW)
endif()

project(cmark-gfm)
# NOTE: we cannot simply version the project due to the use of an invalid
# version (the infixed `.gfm.`).
set(PROJECT_VERSION 0.29.0.gfm.13)

set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 29)
set(PROJECT_VERSION_PATCH 0)
set(PROJECT_VERSION_GFM 13)
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.gfm.${PROJECT_VERSION_GFM})
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED YES)
set(CMAKE_C_EXTENSIONS NO)

set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)

include("FindAsan.cmake")
include("CheckFileOffsetBits.cmake")
set(CMAKE_INCLUDE_CURRENT_DIR YES)

option(CMARK_FUZZ_QUADRATIC "Build quadratic fuzzing harness" OFF)
option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)
option(CMARK_THREADING "Add locks around static accesses" OFF)

if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "Do not build in-source.\nPlease remove CMakeCache.txt and the CMakeFiles/ directory.\nThen: mkdir build ; cd build ; cmake .. ; make")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Profile Release Asan Ubsan." FORCE)
endif(NOT CMAKE_BUILD_TYPE)

option(CMARK_TESTS "Build cmark-gfm tests and enable testing" ON)
option(CMARK_STATIC "Build static libcmark-gfm library" ON)
option(CMARK_SHARED "Build shared libcmark-gfm library" ON)
option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)
option(CMARK_THREADING "Add locks around static accesses" OFF)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)

include(CheckFileOffsetBits)
include(CTest)
include(FindAsan)
if(CMARK_THREADING)
set(THREADS_PREFER_PTHREAD_FLAG YES)
include(FindThreads)
add_compile_definitions(CMARK_THREADING)
endif()
include(GNUInstallDirs)

if(NOT MSVC OR CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
include(InstallRequiredSystemLibraries)
endif()

# set a required C standard so we can load stdbool.h
if(MSVC)
set(CMAKE_C_STANDARD 11)
else()
set(CMAKE_C_STANDARD 99)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/W4>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/WX>)
# FIXME(compnerd) why do we diverge from upstream?
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd5105>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4706>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4221>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4204>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4100>)
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:_CRT_SECURE_NO_WARNINGS>)
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES Clang)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wall>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wextra>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-unused-parameter>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-pedantic>)
endif()
set(CMAKE_C_STANDARD_REQUIRED YES)

# Use CMake's generated headers instead of the Swift package prebuilt ones
add_compile_definitions(CMARK_USE_CMAKE_HEADERS)
if(CMAKE_BUILD_TYPE STREQUAL "Ubsan")
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=undefined>)
endif()

option(CMARK_FUZZ_QUADRATIC "Build quadratic fuzzing harness" OFF)
# Check integrity of node structure when compiled as debug
add_compile_definitions($<$<CONFIG:Debug>:CMARK_DEBUG_NODES>)
# FIXME(compnerd) why do we not use `!defined(NDEBUG)`?
add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)

add_compile_options($<$<AND:$<CONFIG:PROFILE>,$<COMPILE_LANGUAGE:C>>:-pg>)

if(CMARK_LIB_FUZZER)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize-coverage=trace-pc-guard>)
endif()

if(CMARK_FUZZ_QUADRATIC)
set(FUZZER_FLAGS "-fsanitize=fuzzer-no-link,address -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FUZZER_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FUZZER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FUZZER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FUZZER_FLAGS}")
# FIXME(compnerd) why do we enable debug information?
add_compile_options($<$<COMPILE_LANGUAGE:C>:-g>)
# FIXME(compnerd) why do we use fuzzer-no-link with a custom variable for the
# runtime rather than `-fsanitize=fuzzer,address`?
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=fuzzer-no-link,address>)
add_link_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=address>)
endif()

check_file_offset_bits()

add_subdirectory(src)
add_subdirectory(extensions)
if(CMARK_TESTS AND (CMARK_SHARED OR CMARK_STATIC))
add_subdirectory(api_test)
# TODO(compnerd) should this be enabled for MinGW, which sets CMAKE_SYSTEM_NAME
# to Windows, but defines `MINGW`.
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
add_subdirectory(man)
endif()
add_subdirectory(man)
if(CMARK_TESTS)
enable_testing()
if(BUILD_TESTING)
add_subdirectory(test testdir)
add_subdirectory(api_test)
endif()
if(CMARK_FUZZ_QUADRATIC)
add_subdirectory(fuzz)
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Profile Release Asan Ubsan." FORCE)
endif(NOT CMAKE_BUILD_TYPE)
export(TARGETS libcmark-gfm libcmark-gfm-extensions
FILE cmark-gfmConfig.cmake)

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ prof:
afl:
@[ -n "$(AFL_PATH)" ] || { echo '$$AFL_PATH not set'; false; }
mkdir -p $(BUILDDIR)
cd $(BUILDDIR) && cmake .. -DCMARK_TESTS=0 -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang
cd $(BUILDDIR) && cmake .. -DBUILD_TESTING=NO -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang
$(MAKE)
$(AFL_PATH)/afl-fuzz \
-i test/afl_test_cases \
Expand Down
21 changes: 5 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,19 @@
import PackageDescription

#if os(Windows)
#if arch(i386) || arch(x86_64)
var cSettings: [CSetting] = [
.define("_X86_", .when(platforms: [.windows])),
]
#elseif arch(arm) || arch(arm64)
var cSettings: [CSetting] = [
.define("_ARM_", .when(platforms: [.windows])),
]
#else
#error("unsupported architecture")
#endif
// When building the library on Windows, we do not have proper control of
// whether it is being built statically or dynamically. However, given the
// current default of static, we will assume that we are building
// statically. More importantly, should this not hold, this will fail at
// link time.
cSettings += [
let cSettings: [CSetting] = [
.define("CMARK_GFM_STATIC_DEFINE", .when(platforms: [.windows])),
.define("CMARK_GFM_EXTENSIONS_STATIC_DEFINE", .when(platforms: [.windows])),
.define("CMARK_THREADING"),
]
#else
let cSettings: [CSetting] = []
let cSettings: [CSetting] = [
.define("CMARK_THREADING"),
]
#endif

let package = Package(
Expand All @@ -50,9 +41,7 @@ let package = Package(
exclude: [
"scanners.re",
"libcmark-gfm.pc.in",
"config.h.in",
"CMakeLists.txt",
"cmark-gfm_version.h.in",
],
cSettings: cSettings
),
Expand Down
24 changes: 7 additions & 17 deletions api_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,12 @@ include_directories(
${PROJECT_SOURCE_DIR}/extensions/include
${PROJECT_BINARY_DIR}/extensions
)
if(CMARK_SHARED)
target_link_libraries(api_test libcmark-gfm-extensions libcmark-gfm)
else()
target_link_libraries(api_test libcmark-gfm-extensions_static libcmark-gfm_static)
endif()
target_link_libraries(api_test PRIVATE
libcmark-gfm
libcmark-gfm-extensions)

# Compiler flags
if(MSVC)
# Force to always compile with W4
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706 /wd5105 /D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP")
elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic")
add_test(NAME api_test COMMAND api_test)
if(WIN32 AND BUILD_SHARED_LIBS)
set_tests_properties(api_test PROPERTIES
ENVIRONMENT "PATH=$<TARGET_FILE_DIR:libcmark-gfm>;$<TARGET_FILE_DIR:libcmark-gfm-extensions>;$ENV{PATH}")
endif()
3 changes: 2 additions & 1 deletion api_test/main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -1387,7 +1388,7 @@ static void parser_interrupt(test_batch_runner *runner) {
cmark_gfm_core_extensions_ensure_registered();

cmark_syntax_extension *my_ext = cmark_syntax_extension_new("interrupt");
cmark_syntax_extension_set_private(my_ext, run_inner_parser, NULL);
cmark_syntax_extension_set_private(my_ext, (void *)&run_inner_parser, NULL);
cmark_syntax_extension_set_match_inline_func(my_ext, reentrant_parse_inline_ext);

cmark_parser *parser = cmark_parser_new(CMARK_OPT_DEFAULT);
Expand Down
7 changes: 4 additions & 3 deletions bin/main.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <stdlib.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "cmark-gfm_config.h"

#include "cmark-gfm.h"
#include "node.h"
#include "cmark-gfm-extension_api.h"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading