Skip to content

Commit f91a3a0

Browse files
committed
feat: add partial support for WASI
This change allows building the `cmark-gfm` target for both `wasm32-unknown-wasi` and `wasm32-unknown-wasip1-threads`. The other targets are not tested. The differences between two target triples: - `wasm32-unknown-wasi` - C - can import `unistd.h` - has `__wasi__` - does not have `__unix__` - **does not have `_REENTRANT`** - **does not have `_POSIX_THREADS`** - **does not support pthreads API at all** - Swift - can use `#if os(WASI)` - SwiftPM - `BuildSettingsCondition`'s `Platform` is `.wasi` - `wasm32-unknown-wasip1-threads` - C - can import `unistd.h` - has `__wasi__` - does not have `__unix__` - **has `_REENTRANT` (defined in wasi-libc)** - **has `_POSIX_THREADS` (defined in wasi-libc)** - **supports a subset of pthreads API** - Swift - can use `#if os(WASI)` - SwiftPM - `BuildSettingsCondition`'s `Platform` is `.wasi`
1 parent b022b08 commit f91a3a0

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

Package.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ import PackageDescription
1111
// link time.
1212
let cSettings: [CSetting] = [
1313
.define("CMARK_GFM_STATIC_DEFINE", .when(platforms: [.windows])),
14-
.define("CMARK_THREADING"),
1514
]
1615
#else
17-
let cSettings: [CSetting] = [
18-
.define("CMARK_THREADING"),
19-
]
16+
let cSettings: [CSetting] = []
2017
#endif
2118

2219
let package = Package(

api_test/harness.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void INT_EQ(test_batch_runner *runner, int got, int expected, const char *msg,
5454
}
5555
}
5656

57-
#ifndef _WIN32
57+
#if !defined(_WIN32) && !defined(__wasi__)
5858
#include <unistd.h>
5959

6060
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,
7979
va_end(ap);
8080

8181
if (!cond) {
82-
#ifndef _WIN32
82+
#if !defined(_WIN32) && !defined(__wasi__)
8383
char *got_fn = write_tmp("actual\n", got);
8484
char *expected_fn = write_tmp("expected\n", expected);
8585
char buf[1024];

src/include/mutex.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33

44
#include <stdbool.h>
55

6+
#ifndef CMARK_THREADING
7+
#if !defined(__wasi__) || defined(_REENTRANT)
8+
#define CMARK_THREADING
9+
#endif
10+
#endif
11+
612
#ifdef CMARK_THREADING
713

8-
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
14+
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__wasi__)
915
#include <unistd.h>
1016
#endif
1117

0 commit comments

Comments
 (0)