From aefae11c0ddab2e47d2a00aee00a257f93b8ef30 Mon Sep 17 00:00:00 2001 From: Will Lillis Date: Sat, 10 Jan 2026 04:20:16 -0500 Subject: [PATCH] fix(build): define `_BSD_SOURCE` System endian conversion macros are gated behind this feature flag for older versions of GLIBC. `_BSD_SOURCE` and `_SVID_SOURCE` were deprecated and replaced with `_DEFAULT_SOURCE` starting with GLIBC 2.19. --- 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 b40ac55a..f11895c0 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 _DARWIN_C_SOURCE) +target_compile_definitions(tree-sitter PRIVATE _POSIX_C_SOURCE=200112L _DEFAULT_SOURCE _BSD_SOURCE _DARWIN_C_SOURCE) include(GNUInstallDirs) diff --git a/Makefile b/Makefile index d0b402f0..2098d275 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 -D_DARWIN_C_SOURCE +override CFLAGS += -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -D_BSD_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 a92d3d14..fb6c6e95 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("_BSD_SOURCE"), .define("_DARWIN_C_SOURCE"), ]), ], diff --git a/build.zig b/build.zig index bd7a0721..9bb1e818 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("_BSD_SOURCE", ""); lib.root_module.addCMacro("_DARWIN_C_SOURCE", ""); if (wasm) { diff --git a/crates/xtask/src/build_wasm.rs b/crates/xtask/src/build_wasm.rs index 183718a6..fbb231ce 100644 --- a/crates/xtask/src/build_wasm.rs +++ b/crates/xtask/src/build_wasm.rs @@ -199,6 +199,7 @@ pub fn run_wasm(args: &BuildWasm) -> Result<()> { "-D", "NDEBUG=", "-D", "_POSIX_C_SOURCE=200112L", "-D", "_DEFAULT_SOURCE=", + "-D", "_BSD_SOURCE=", "-D", "_DARWIN_C_SOURCE=", "-I", "lib/src", "-I", "lib/include", diff --git a/lib/binding_rust/build.rs b/lib/binding_rust/build.rs index 624001bc..57c5bc94 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("_BSD_SOURCE", None) .define("_DARWIN_C_SOURCE", None) .warnings(false) .file(src_path.join("lib.c"))