From 95ab17e444bf30f08dc9206164c0c3aee1f8ecca Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 21 Sep 2025 23:07:59 -0400 Subject: [PATCH] build: define _DARWIN_C_SOURCE --- CMakeLists.txt | 2 +- Makefile | 2 +- Package.swift | 1 + build.zig | 1 + crates/xtask/src/build_wasm.rs | 1 + lib/binding_rust/build.rs | 1 + 6 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc8bf049..f0d1d813 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ set_target_properties(tree-sitter SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" DEFINE_SYMBOL "") -target_compile_definitions(tree-sitter PRIVATE _POSIX_C_SOURCE=200112L _DEFAULT_SOURCE) +target_compile_definitions(tree-sitter PRIVATE _POSIX_C_SOURCE=200112L _DEFAULT_SOURCE _DARWIN_C_SOURCE) include(GNUInstallDirs) diff --git a/Makefile b/Makefile index abd765b1..f8106fa0 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ OBJ := $(SRC:.c=.o) ARFLAGS := rcs CFLAGS ?= -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types override CFLAGS += -std=c11 -fPIC -fvisibility=hidden -override CFLAGS += -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE +override CFLAGS += -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE override CFLAGS += -Ilib/src -Ilib/src/wasm -Ilib/include # ABI versioning diff --git a/Package.swift b/Package.swift index 572ba684..a92d3d14 100644 --- a/Package.swift +++ b/Package.swift @@ -27,6 +27,7 @@ let package = Package( .headerSearchPath("src"), .define("_POSIX_C_SOURCE", to: "200112L"), .define("_DEFAULT_SOURCE"), + .define("_DARWIN_C_SOURCE"), ]), ], cLanguageStandard: .c11 diff --git a/build.zig b/build.zig index 66a448cb..bd7a0721 100644 --- a/build.zig +++ b/build.zig @@ -40,6 +40,7 @@ pub fn build(b: *std.Build) !void { lib.root_module.addCMacro("_POSIX_C_SOURCE", "200112L"); lib.root_module.addCMacro("_DEFAULT_SOURCE", ""); + lib.root_module.addCMacro("_DARWIN_C_SOURCE", ""); if (wasm) { if (b.lazyDependency(wasmtimeDep(target.result), .{})) |wasmtime| { diff --git a/crates/xtask/src/build_wasm.rs b/crates/xtask/src/build_wasm.rs index 67ca59d6..8b1f78d5 100644 --- a/crates/xtask/src/build_wasm.rs +++ b/crates/xtask/src/build_wasm.rs @@ -195,6 +195,7 @@ pub fn run_wasm(args: &BuildWasm) -> Result<()> { "-D", "NDEBUG=", "-D", "_POSIX_C_SOURCE=200112L", "-D", "_DEFAULT_SOURCE=", + "-D", "_DARWIN_C_SOURCE=", "-I", "lib/src", "-I", "lib/include", "--js-library", "lib/binding_web/lib/imports.js", diff --git a/lib/binding_rust/build.rs b/lib/binding_rust/build.rs index 7268d615..624001bc 100644 --- a/lib/binding_rust/build.rs +++ b/lib/binding_rust/build.rs @@ -49,6 +49,7 @@ fn main() { .include(&include_path) .define("_POSIX_C_SOURCE", "200112L") .define("_DEFAULT_SOURCE", None) + .define("_DARWIN_C_SOURCE", None) .warnings(false) .file(src_path.join("lib.c")) .compile("tree-sitter");