Skip to content

Commit 595876b

Browse files
authored
Merge pull request #69 from compnerd/swift-markdown-support
Swift markdown support
2 parents 3bc2f3e + b59a9a3 commit 595876b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+494
-816
lines changed

CMakeLists.txt

Lines changed: 87 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,114 @@
11
cmake_minimum_required(VERSION 3.12)
2+
3+
if(POLICY CMP0063)
4+
cmake_policy(SET CMP0063 NEW)
5+
endif()
6+
7+
if(POLICY CMP0092)
8+
cmake_policy(SET CMP0092 NEW)
9+
endif()
10+
211
project(cmark-gfm)
12+
# NOTE: we cannot simply version the project due to the use of an invalid
13+
# version (the infixed `.gfm.`).
14+
set(PROJECT_VERSION 0.29.0.gfm.13)
315

4-
set(PROJECT_VERSION_MAJOR 0)
5-
set(PROJECT_VERSION_MINOR 29)
6-
set(PROJECT_VERSION_PATCH 0)
7-
set(PROJECT_VERSION_GFM 13)
8-
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.gfm.${PROJECT_VERSION_GFM})
16+
set(CMAKE_C_STANDARD 99)
17+
set(CMAKE_C_STANDARD_REQUIRED YES)
18+
set(CMAKE_C_EXTENSIONS NO)
19+
20+
set(CMAKE_C_VISIBILITY_PRESET hidden)
21+
set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)
922

10-
include("FindAsan.cmake")
11-
include("CheckFileOffsetBits.cmake")
23+
set(CMAKE_INCLUDE_CURRENT_DIR YES)
24+
25+
option(CMARK_FUZZ_QUADRATIC "Build quadratic fuzzing harness" OFF)
26+
option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)
27+
option(CMARK_THREADING "Add locks around static accesses" OFF)
1228

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

17-
option(CMARK_TESTS "Build cmark-gfm tests and enable testing" ON)
18-
option(CMARK_STATIC "Build static libcmark-gfm library" ON)
19-
option(CMARK_SHARED "Build shared libcmark-gfm library" ON)
20-
option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)
21-
option(CMARK_THREADING "Add locks around static accesses" OFF)
37+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
38+
39+
include(CheckFileOffsetBits)
40+
include(CTest)
41+
include(FindAsan)
42+
if(CMARK_THREADING)
43+
set(THREADS_PREFER_PTHREAD_FLAG YES)
44+
include(FindThreads)
45+
add_compile_definitions(CMARK_THREADING)
46+
endif()
47+
include(GNUInstallDirs)
48+
49+
if(NOT MSVC OR CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
50+
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
51+
include(InstallRequiredSystemLibraries)
52+
endif()
2253

23-
# set a required C standard so we can load stdbool.h
2454
if(MSVC)
25-
set(CMAKE_C_STANDARD 11)
26-
else()
27-
set(CMAKE_C_STANDARD 99)
55+
add_compile_options($<$<COMPILE_LANGUAGE:C>:/W4>)
56+
add_compile_options($<$<COMPILE_LANGUAGE:C>:/WX>)
57+
# FIXME(compnerd) why do we diverge from upstream?
58+
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd5105>)
59+
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4706>)
60+
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4221>)
61+
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4204>)
62+
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4100>)
63+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:_CRT_SECURE_NO_WARNINGS>)
64+
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES Clang)
65+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wall>)
66+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wextra>)
67+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-unused-parameter>)
68+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-pedantic>)
2869
endif()
29-
set(CMAKE_C_STANDARD_REQUIRED YES)
3070

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

34-
option(CMARK_FUZZ_QUADRATIC "Build quadratic fuzzing harness" OFF)
75+
# Check integrity of node structure when compiled as debug
76+
add_compile_definitions($<$<CONFIG:Debug>:CMARK_DEBUG_NODES>)
77+
# FIXME(compnerd) why do we not use `!defined(NDEBUG)`?
78+
add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
79+
80+
add_compile_options($<$<AND:$<CONFIG:PROFILE>,$<COMPILE_LANGUAGE:C>>:-pg>)
81+
82+
if(CMARK_LIB_FUZZER)
83+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize-coverage=trace-pc-guard>)
84+
endif()
3585

3686
if(CMARK_FUZZ_QUADRATIC)
37-
set(FUZZER_FLAGS "-fsanitize=fuzzer-no-link,address -g")
38-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FUZZER_FLAGS}")
39-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FUZZER_FLAGS}")
40-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FUZZER_FLAGS}")
41-
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FUZZER_FLAGS}")
87+
# FIXME(compnerd) why do we enable debug information?
88+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-g>)
89+
# FIXME(compnerd) why do we use fuzzer-no-link with a custom variable for the
90+
# runtime rather than `-fsanitize=fuzzer,address`?
91+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=fuzzer-no-link,address>)
92+
add_link_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=address>)
4293
endif()
4394

95+
check_file_offset_bits()
96+
4497
add_subdirectory(src)
4598
add_subdirectory(extensions)
46-
if(CMARK_TESTS AND (CMARK_SHARED OR CMARK_STATIC))
47-
add_subdirectory(api_test)
99+
# TODO(compnerd) should this be enabled for MinGW, which sets CMAKE_SYSTEM_NAME
100+
# to Windows, but defines `MINGW`.
101+
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
102+
add_subdirectory(man)
48103
endif()
49-
add_subdirectory(man)
50-
if(CMARK_TESTS)
51-
enable_testing()
104+
if(BUILD_TESTING)
52105
add_subdirectory(test testdir)
106+
add_subdirectory(api_test)
53107
endif()
54108
if(CMARK_FUZZ_QUADRATIC)
55109
add_subdirectory(fuzz)
56110
endif()
57111

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

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ prof:
7575
afl:
7676
@[ -n "$(AFL_PATH)" ] || { echo '$$AFL_PATH not set'; false; }
7777
mkdir -p $(BUILDDIR)
78-
cd $(BUILDDIR) && cmake .. -DCMARK_TESTS=0 -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang
78+
cd $(BUILDDIR) && cmake .. -DBUILD_TESTING=NO -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang
7979
$(MAKE)
8080
$(AFL_PATH)/afl-fuzz \
8181
-i test/afl_test_cases \

Package.swift

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,19 @@
44
import PackageDescription
55

66
#if os(Windows)
7-
#if arch(i386) || arch(x86_64)
8-
var cSettings: [CSetting] = [
9-
.define("_X86_", .when(platforms: [.windows])),
10-
]
11-
#elseif arch(arm) || arch(arm64)
12-
var cSettings: [CSetting] = [
13-
.define("_ARM_", .when(platforms: [.windows])),
14-
]
15-
#else
16-
#error("unsupported architecture")
17-
#endif
187
// When building the library on Windows, we do not have proper control of
198
// whether it is being built statically or dynamically. However, given the
209
// current default of static, we will assume that we are building
2110
// statically. More importantly, should this not hold, this will fail at
2211
// link time.
23-
cSettings += [
12+
let cSettings: [CSetting] = [
2413
.define("CMARK_GFM_STATIC_DEFINE", .when(platforms: [.windows])),
25-
.define("CMARK_GFM_EXTENSIONS_STATIC_DEFINE", .when(platforms: [.windows])),
14+
.define("CMARK_THREADING"),
2615
]
2716
#else
28-
let cSettings: [CSetting] = []
17+
let cSettings: [CSetting] = [
18+
.define("CMARK_THREADING"),
19+
]
2920
#endif
3021

3122
let package = Package(
@@ -50,9 +41,7 @@ let package = Package(
5041
exclude: [
5142
"scanners.re",
5243
"libcmark-gfm.pc.in",
53-
"config.h.in",
5444
"CMakeLists.txt",
55-
"cmark-gfm_version.h.in",
5645
],
5746
cSettings: cSettings
5847
),

api_test/CMakeLists.txt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,12 @@ include_directories(
1010
${PROJECT_SOURCE_DIR}/extensions/include
1111
${PROJECT_BINARY_DIR}/extensions
1212
)
13-
if(CMARK_SHARED)
14-
target_link_libraries(api_test libcmark-gfm-extensions libcmark-gfm)
15-
else()
16-
target_link_libraries(api_test libcmark-gfm-extensions_static libcmark-gfm_static)
17-
endif()
13+
target_link_libraries(api_test PRIVATE
14+
libcmark-gfm
15+
libcmark-gfm-extensions)
1816

19-
# Compiler flags
20-
if(MSVC)
21-
# Force to always compile with W4
22-
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
23-
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
24-
else()
25-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
26-
endif()
27-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706 /wd5105 /D_CRT_SECURE_NO_WARNINGS")
28-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP")
29-
elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
30-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic")
17+
add_test(NAME api_test COMMAND api_test)
18+
if(WIN32 AND BUILD_SHARED_LIBS)
19+
set_tests_properties(api_test PROPERTIES
20+
ENVIRONMENT "PATH=$<TARGET_FILE_DIR:libcmark-gfm>;$<TARGET_FILE_DIR:libcmark-gfm-extensions>;$ENV{PATH}")
3121
endif()

api_test/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdbool.h>
12
#include <stdio.h>
23
#include <stdlib.h>
34
#include <string.h>
@@ -1387,7 +1388,7 @@ static void parser_interrupt(test_batch_runner *runner) {
13871388
cmark_gfm_core_extensions_ensure_registered();
13881389

13891390
cmark_syntax_extension *my_ext = cmark_syntax_extension_new("interrupt");
1390-
cmark_syntax_extension_set_private(my_ext, run_inner_parser, NULL);
1391+
cmark_syntax_extension_set_private(my_ext, (void *)&run_inner_parser, NULL);
13911392
cmark_syntax_extension_set_match_inline_func(my_ext, reentrant_parse_inline_ext);
13921393

13931394
cmark_parser *parser = cmark_parser_new(CMARK_OPT_DEFAULT);

bin/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#include <stdlib.h>
1+
#include <errno.h>
2+
#include <stdbool.h>
23
#include <stdio.h>
4+
#include <stdlib.h>
35
#include <string.h>
4-
#include <errno.h>
5-
#include "cmark-gfm_config.h"
6+
67
#include "cmark-gfm.h"
78
#include "node.h"
89
#include "cmark-gfm-extension_api.h"
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)