Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -76,6 +75,8 @@ endif()
add_compile_definitions($<$<CONFIG:Debug>:CMARK_DEBUG_NODES>)
# FIXME(compnerd) why do we not use `!defined(NDEBUG)`?
add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
# Use CMake's generated headers instead of the Swift package prebuilt ones
add_compile_definitions(CMARK_USE_CMAKE_HEADERS)

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

Expand Down
6 changes: 2 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -41,6 +38,7 @@ let package = Package(
exclude: [
"scanners.re",
"libcmark-gfm.pc.in",
"config.h.in",
"CMakeLists.txt",
],
cSettings: cSettings
Expand Down
4 changes: 2 additions & 2 deletions api_test/harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <unistd.h>

static char *write_tmp(char const *header, char const *data) {
Expand All @@ -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];
Expand Down
1 change: 1 addition & 0 deletions bin/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>

#include "cmark-gfm_config.h"
#include "cmark-gfm.h"
#include "node.h"
#include "cmark-gfm-extension_api.h"
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdlib.h>
#include <string.h>

#include "cmark-gfm_config.h"
#include "cmark_ctype.h"
#include "buffer.h"

Expand Down
1 change: 1 addition & 0 deletions src/commonmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>

#include "cmark-gfm_config.h"
#include "cmark-gfm.h"
#include "node.h"
#include "buffer.h"
Expand Down
14 changes: 14 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef CMARK_CONFIG_H
#define CMARK_CONFIG_H

#ifdef __cplusplus
extern "C" {
#endif

#cmakedefine01 CMARK_THREADING

#ifdef __cplusplus
}
#endif

#endif
1 change: 1 addition & 0 deletions src/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string.h>

#include "cmark_ctype.h"
#include "cmark-gfm_config.h"
#include "cmark-gfm.h"
#include "houdini.h"
#include "scanners.h"
Expand Down
1 change: 1 addition & 0 deletions src/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string.h>
#include <limits.h>
#include <stdint.h>
#include "cmark-gfm_config.h"
#include "cmark-gfm.h"

#ifdef __cplusplus
Expand Down
29 changes: 29 additions & 0 deletions src/include/cmark-gfm_config.h
Original file line number Diff line number Diff line change
@@ -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 */
2 changes: 1 addition & 1 deletion src/include/houdini.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CMARK_HOUDINI_H

#include <stdint.h>

#include "cmark-gfm_config.h"
#include "buffer.h"

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions src/include/inlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdbool.h>
#include <stdlib.h>

#include "cmark-gfm_config.h"
#include "references.h"

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions src/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/include/mutex.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#ifndef CMARK_MUTEX_H
#define CMARK_MUTEX_H

#include "cmark-gfm_config.h"

#include <stdbool.h>

#ifdef CMARK_THREADING
#if CMARK_THREADING

#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__wasi__)
#include <unistd.h>
#endif
Comment on lines +10 to 12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point i'm starting to wonder if we can just get away with just checking for the existence of unistd.h instead of probing for different compilation environments:

Suggested change
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__wasi__)
#include <unistd.h>
#endif
#if defined(__has_include)
#if __has_include(<unistd.h>)
#include <unistd.h>
#endif
#endif

It looks like both Clang and GCC have the __has_include macro, so this should probably cover our bases for any other new platform over time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QuietMisdreavus I really appreciate your review.

As you said, using the __has_include macro makes the code more robust against future changes, but I hesitate to use it.

Because the __has_include macro is standard in C++17 and C23, but not in C99. This repository appears to be compiled as C99, at least in CMake.

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED YES)
set(CMAKE_C_EXTENSIONS NO)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh heck, i didn't realize it was tied to a C standard. It's likely the C99 requirement is inherited from GitHub-Flavored Markdown (or even CommonMark) so i would hesitate to change it.

In that case, we can merge this as-is and live with the ever-growing list of Unix-like platforms here. 😅


Expand Down
1 change: 1 addition & 0 deletions src/include/syntax_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "cmark-gfm.h"
#include "cmark-gfm-extension_api.h"
#include "cmark-gfm_config.h"

#include <stdbool.h>

Expand Down
1 change: 1 addition & 0 deletions src/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string.h>

#include "cmark_ctype.h"
#include "cmark-gfm_config.h"
#include "node.h"
#include "parser.h"
#include "references.h"
Expand Down
1 change: 1 addition & 0 deletions src/iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdbool.h>
#include <stdlib.h>

#include "cmark-gfm_config.h"
#include "node.h"
#include "cmark-gfm.h"
#include "iterator.h"
Expand Down
1 change: 1 addition & 0 deletions src/latex.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>

#include "cmark-gfm_config.h"
#include "cmark-gfm.h"
#include "node.h"
#include "buffer.h"
Expand Down
1 change: 1 addition & 0 deletions src/man.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>

#include "cmark-gfm_config.h"
#include "cmark-gfm.h"
#include "node.h"
#include "buffer.h"
Expand Down
1 change: 1 addition & 0 deletions src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>

#include "cmark-gfm_config.h"
#include "mutex.h"
#include "node.h"
#include "syntax_extension.h"
Expand Down
1 change: 1 addition & 0 deletions src/registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>

#include "cmark-gfm_config.h"
#include "cmark-gfm.h"
#include "mutex.h"
#include "syntax_extension.h"
Expand Down
1 change: 1 addition & 0 deletions src/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>

#include "cmark-gfm_config.h"
#include "cmark-gfm.h"
#include "node.h"
#include "buffer.h"
Expand Down