diff --git a/CMakeLists.txt b/CMakeLists.txt index 23eca3c50..e40ca1633 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,6 @@ include(FindAsan) if(CMARK_THREADING) set(THREADS_PREFER_PTHREAD_FLAG YES) include(FindThreads) - add_compile_definitions(CMARK_THREADING) endif() include(GNUInstallDirs) @@ -76,6 +75,8 @@ endif() add_compile_definitions($<$:CMARK_DEBUG_NODES>) # FIXME(compnerd) why do we not use `!defined(NDEBUG)`? add_compile_definitions($<$:DEBUG>) +# Use CMake's generated headers instead of the Swift package prebuilt ones +add_compile_definitions(CMARK_USE_CMAKE_HEADERS) add_compile_options($<$,$>:-pg>) diff --git a/Package.swift b/Package.swift index f1acc5f3a..6cdf00ff5 100644 --- a/Package.swift +++ b/Package.swift @@ -11,12 +11,9 @@ import PackageDescription // link time. let cSettings: [CSetting] = [ .define("CMARK_GFM_STATIC_DEFINE", .when(platforms: [.windows])), - .define("CMARK_THREADING"), ] #else - let cSettings: [CSetting] = [ - .define("CMARK_THREADING"), - ] + let cSettings: [CSetting] = [] #endif let package = Package( @@ -41,6 +38,7 @@ let package = Package( exclude: [ "scanners.re", "libcmark-gfm.pc.in", + "config.h.in", "CMakeLists.txt", ], cSettings: cSettings diff --git a/api_test/harness.c b/api_test/harness.c index f561aeace..a00ae9eff 100644 --- a/api_test/harness.c +++ b/api_test/harness.c @@ -54,7 +54,7 @@ void INT_EQ(test_batch_runner *runner, int got, int expected, const char *msg, } } -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__wasi__) #include static char *write_tmp(char const *header, char const *data) { @@ -79,7 +79,7 @@ void STR_EQ(test_batch_runner *runner, const char *got, const char *expected, va_end(ap); if (!cond) { -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__wasi__) char *got_fn = write_tmp("actual\n", got); char *expected_fn = write_tmp("expected\n", expected); char buf[1024]; diff --git a/bin/main.c b/bin/main.c index 0b523596c..46c54bb33 100644 --- a/bin/main.c +++ b/bin/main.c @@ -4,6 +4,7 @@ #include #include +#include "cmark-gfm_config.h" #include "cmark-gfm.h" #include "node.h" #include "cmark-gfm-extension_api.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 54499cb1a..deee8dcbb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,6 @@ +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/config.h) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark-gfm.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libcmark-gfm.pc @ONLY) @@ -68,6 +71,7 @@ install(FILES include/chunk.h include/cmark_ctype.h include/cmark-gfm.h + include/cmark-gfm_config.h include/cmark-gfm-extension_api.h include/cmark-gfm_version.h include/export.h diff --git a/src/blocks.c b/src/blocks.c index 6467a3a59..1efd8fd01 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -13,6 +13,7 @@ #include "cmark_ctype.h" #include "syntax_extension.h" +#include "cmark-gfm_config.h" #include "parser.h" #include "cmark-gfm.h" #include "node.h" diff --git a/src/buffer.c b/src/buffer.c index aeca03d09..5adfa3054 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -7,6 +7,7 @@ #include #include +#include "cmark-gfm_config.h" #include "cmark_ctype.h" #include "buffer.h" diff --git a/src/commonmark.c b/src/commonmark.c index a5aa74728..dee18b4d9 100644 --- a/src/commonmark.c +++ b/src/commonmark.c @@ -5,6 +5,7 @@ #include #include +#include "cmark-gfm_config.h" #include "cmark-gfm.h" #include "node.h" #include "buffer.h" diff --git a/src/config.h.in b/src/config.h.in new file mode 100644 index 000000000..ad2c4b6c8 --- /dev/null +++ b/src/config.h.in @@ -0,0 +1,14 @@ +#ifndef CMARK_CONFIG_H +#define CMARK_CONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#cmakedefine01 CMARK_THREADING + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/html.c b/src/html.c index 4d5624ae7..cb9ad6801 100644 --- a/src/html.c +++ b/src/html.c @@ -5,6 +5,7 @@ #include #include "cmark_ctype.h" +#include "cmark-gfm_config.h" #include "cmark-gfm.h" #include "houdini.h" #include "scanners.h" diff --git a/src/include/buffer.h b/src/include/buffer.h index 56a28feb5..3926b6549 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -6,6 +6,7 @@ #include #include #include +#include "cmark-gfm_config.h" #include "cmark-gfm.h" #ifdef __cplusplus diff --git a/src/include/cmark-gfm_config.h b/src/include/cmark-gfm_config.h new file mode 100644 index 000000000..4a17341f3 --- /dev/null +++ b/src/include/cmark-gfm_config.h @@ -0,0 +1,29 @@ +#ifndef CMARK_CONFIG_H +#define CMARK_CONFIG_H + +#ifdef CMARK_USE_CMAKE_HEADERS +// if the CMake config header exists, use that instead of this Swift package prebuilt one +// we need to undefine the header guard, since config.h uses the same one +#undef CMARK_CONFIG_H +#include "config.h" +#else + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef CMARK_THREADING +#if defined(__wasi__) && !defined(_REENTRANT) +#define CMARK_THREADING 0 +#else +#define CMARK_THREADING 1 +#endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* not CMARK_USE_CMAKE_HEADERS */ + +#endif /* not CMARK_CONFIG_H */ diff --git a/src/include/houdini.h b/src/include/houdini.h index 61a3cd639..e55b77fd8 100644 --- a/src/include/houdini.h +++ b/src/include/houdini.h @@ -2,7 +2,7 @@ #define CMARK_HOUDINI_H #include - +#include "cmark-gfm_config.h" #include "buffer.h" #ifdef __cplusplus diff --git a/src/include/inlines.h b/src/include/inlines.h index b99acfc5f..84090e89d 100644 --- a/src/include/inlines.h +++ b/src/include/inlines.h @@ -4,6 +4,7 @@ #include #include +#include "cmark-gfm_config.h" #include "references.h" #ifdef __cplusplus diff --git a/src/include/module.modulemap b/src/include/module.modulemap index 16c65818f..549f1e499 100644 --- a/src/include/module.modulemap +++ b/src/include/module.modulemap @@ -1,5 +1,6 @@ module cmark_gfm { header "cmark-gfm.h" + header "cmark-gfm_config.h" header "cmark-gfm-extension_api.h" header "buffer.h" header "chunk.h" diff --git a/src/include/mutex.h b/src/include/mutex.h index 59427f345..31933af68 100644 --- a/src/include/mutex.h +++ b/src/include/mutex.h @@ -1,11 +1,13 @@ #ifndef CMARK_MUTEX_H #define CMARK_MUTEX_H +#include "cmark-gfm_config.h" + #include -#ifdef CMARK_THREADING +#if CMARK_THREADING -#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__wasi__) #include #endif diff --git a/src/include/syntax_extension.h b/src/include/syntax_extension.h index de8d3d62a..4ccb6ce35 100644 --- a/src/include/syntax_extension.h +++ b/src/include/syntax_extension.h @@ -3,6 +3,7 @@ #include "cmark-gfm.h" #include "cmark-gfm-extension_api.h" +#include "cmark-gfm_config.h" #include diff --git a/src/inlines.c b/src/inlines.c index 6e51feb0c..5fee895d6 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -4,6 +4,7 @@ #include #include "cmark_ctype.h" +#include "cmark-gfm_config.h" #include "node.h" #include "parser.h" #include "references.h" diff --git a/src/iterator.c b/src/iterator.c index e7cc64582..d8c0eade5 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -2,6 +2,7 @@ #include #include +#include "cmark-gfm_config.h" #include "node.h" #include "cmark-gfm.h" #include "iterator.h" diff --git a/src/latex.c b/src/latex.c index 0fc607975..b4df8d0d4 100644 --- a/src/latex.c +++ b/src/latex.c @@ -4,6 +4,7 @@ #include #include +#include "cmark-gfm_config.h" #include "cmark-gfm.h" #include "node.h" #include "buffer.h" diff --git a/src/man.c b/src/man.c index 1baceb4c5..b92cdb319 100644 --- a/src/man.c +++ b/src/man.c @@ -4,6 +4,7 @@ #include #include +#include "cmark-gfm_config.h" #include "cmark-gfm.h" #include "node.h" #include "buffer.h" diff --git a/src/node.c b/src/node.c index 78fbd6265..967b1b900 100644 --- a/src/node.c +++ b/src/node.c @@ -2,6 +2,7 @@ #include #include +#include "cmark-gfm_config.h" #include "mutex.h" #include "node.h" #include "syntax_extension.h" diff --git a/src/registry.c b/src/registry.c index 090a01c31..91f79530a 100644 --- a/src/registry.c +++ b/src/registry.c @@ -2,6 +2,7 @@ #include #include +#include "cmark-gfm_config.h" #include "cmark-gfm.h" #include "mutex.h" #include "syntax_extension.h" diff --git a/src/xml.c b/src/xml.c index ad46af723..b3ed49b33 100644 --- a/src/xml.c +++ b/src/xml.c @@ -4,6 +4,7 @@ #include #include +#include "cmark-gfm_config.h" #include "cmark-gfm.h" #include "node.h" #include "buffer.h"