Skip to content

Commit 399446c

Browse files
committed
Fix cross-platform JIT build issues on glibc, Windows, and wasm32
1 parent 2ca807d commit 399446c

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/dsl_config.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
#define ME_DSL_WHILE_MAX_ITERS_DEFAULT 10000000LL
3232
#endif
3333

34+
#ifndef ME_DSL_JIT_LIBTCC_DEFAULT_PATH
35+
#define ME_DSL_JIT_LIBTCC_DEFAULT_PATH ""
36+
#endif
37+
38+
#ifndef ME_DSL_JIT_WASM_POS_CACHE_SLOTS
39+
#define ME_DSL_JIT_WASM_POS_CACHE_SLOTS 64
40+
#endif
41+
3442
static inline bool dsl_env_flag_enabled(const char *name, bool default_value) {
3543
const char *env = getenv(name);
3644
if (!env || env[0] == '\0') {

src/dsl_jit_backend_cc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
See LICENSE.txt for details about copyright and rights to use.
99
**********************************************************************/
1010

11+
#ifndef _GNU_SOURCE
12+
#define _GNU_SOURCE
13+
#endif
14+
1115
#include "dsl_jit_bridge_contract.h"
1216
#include "dsl_jit_runtime_internal.h"
1317

src/dsl_jit_backend_libtcc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
See LICENSE.txt for details about copyright and rights to use.
99
**********************************************************************/
1010

11+
#ifndef _GNU_SOURCE
12+
#define _GNU_SOURCE
13+
#endif
14+
1115
#include "dsl_jit_bridge_contract.h"
1216
#include "dsl_jit_runtime_internal.h"
1317

src/dsl_jit_runtime_cache.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@
2020
#define WIN32_LEAN_AND_MEAN
2121
#endif
2222
#include <windows.h>
23+
#include <direct.h>
24+
#include <sys/stat.h>
25+
#ifndef S_ISDIR
26+
#define S_ISDIR(mode) (((mode) & _S_IFDIR) != 0)
27+
#endif
28+
#define me_stat _stat
29+
#define me_mkdir(path, mode) _mkdir(path)
2330
#else
2431
#include <sys/stat.h>
2532
#include <unistd.h>
33+
#define me_stat stat
34+
#define me_mkdir(path, mode) mkdir((path), (mode))
2635
#endif
2736

2837
static uint64_t dsl_jit_hash_bytes(uint64_t h, const void *ptr, size_t n) {
@@ -235,10 +244,10 @@ static bool dsl_jit_ensure_dir(const char *path) {
235244
return false;
236245
}
237246
struct stat st;
238-
if (stat(path, &st) == 0) {
247+
if (me_stat(path, &st) == 0) {
239248
return S_ISDIR(st.st_mode);
240249
}
241-
if (mkdir(path, 0700) == 0) {
250+
if (me_mkdir(path, 0700) == 0) {
242251
return true;
243252
}
244253
if (errno == EEXIST) {
@@ -251,6 +260,19 @@ bool dsl_jit_get_cache_dir(char *out, size_t out_size) {
251260
if (!out || out_size == 0) {
252261
return false;
253262
}
263+
#if defined(_WIN32) || defined(_WIN64)
264+
const char *tmpdir = getenv("TEMP");
265+
if (!tmpdir || tmpdir[0] == '\0') {
266+
tmpdir = getenv("TMP");
267+
}
268+
if (!tmpdir || tmpdir[0] == '\0') {
269+
tmpdir = ".";
270+
}
271+
if (snprintf(out, out_size, "%s\\miniexpr-jit", tmpdir) >= (int)out_size) {
272+
return false;
273+
}
274+
return dsl_jit_ensure_dir(out);
275+
#else
254276
const char *tmpdir = getenv("TMPDIR");
255277
if (!tmpdir || tmpdir[0] == '\0') {
256278
/* Avoid cross-user permission conflicts when TMPDIR is not set. */
@@ -263,6 +285,7 @@ bool dsl_jit_get_cache_dir(char *out, size_t out_size) {
263285
return false;
264286
}
265287
return dsl_jit_ensure_dir(out);
288+
#endif
266289
}
267290

268291
bool dsl_jit_write_text_file(const char *path, const char *text) {

0 commit comments

Comments
 (0)