Skip to content

Commit

Permalink
Zig it
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Aug 14, 2024
1 parent 9984b33 commit ecde100
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions file-events/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.zig-cache/
88 changes: 88 additions & 0 deletions file-events/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const std = @import("std");

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const lib = b.addSharedLibrary(.{ .name = "file-events", .target = target, .optimize = optimize });

const env = std.process.getEnvMap(b.allocator) catch unreachable;
const java_home = env.get("JAVA_HOME") orelse unreachable;
const java_include_path = std.fmt.allocPrint(b.allocator, "{s}/include", .{java_home}) catch unreachable;
const java_darwin_include_path = std.fmt.allocPrint(b.allocator, "{s}/include/darwin", .{java_home}) catch unreachable;

// Add include directories
lib.addIncludePath(b.path("build/generated/sources/headers/java/main"));
lib.addIncludePath(b.path("build/generated/version/header"));
lib.addIncludePath(b.path("src/file-events/headers"));
lib.addSystemIncludePath(.{ .cwd_relative = java_include_path });
lib.addSystemIncludePath(.{ .cwd_relative = java_darwin_include_path });

// Set common C++ compiler flags
const cpp_args = [_][]const u8{
"--std=c++17",
"-g",
"-pedantic",
"-Wall",
"-Wextra",
"-Wformat=2",
"-Werror",
"-Wno-deprecated-declarations",
"-Wno-format-nonliteral",
"-Wno-unguarded-availability-new",
};

// Add source files
lib.addCSourceFiles(.{
.files = &.{
"src/file-events/cpp/apple_fsnotifier.cpp",
"src/file-events/cpp/file-events-version.cpp",
"src/file-events/cpp/generic_fsnotifier.cpp",
"src/file-events/cpp/jni_support.cpp",
"src/file-events/cpp/linux_fsnotifier.cpp",
"src/file-events/cpp/logging.cpp",
"src/file-events/cpp/services.cpp",
"src/file-events/cpp/win_fsnotifier.cpp",
},
.flags = &cpp_args,
});

// Link against libc and libstdc++
lib.linkLibC();
lib.linkLibCpp();

// // Platform-specific configurations
// if (target.os.tag == .macos or target.os.tag == .linux) {
// lib.c_flags.append("-pthread");

// // Set linker flags
// lib.linker_flags.append("-pthread");
// } else if (target.os.tag == .windows) {
// lib.c_flags = &[_][]const u8{
// "/DEBUG",
// "/permissive-",
// "/EShc",
// "/Zi",
// "/FS",
// "/Zc:inline",
// "/Zc:throwingNew",
// "/W3",
// "/WX",
// "/D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING",
// };

// // Set linker flags
// lib.linker_flags = &[_][]const u8{
// "/DEBUG:FULL",
// };
// }

// lib.verbose_cc = true;
// lib.verbose_link = true;

const install = b.addInstallArtifact(lib, .{});

// Ensure the library is built
const build_step = b.step("build", "Build the file-events shared library");
build_step.dependOn(&install.step);
}

0 comments on commit ecde100

Please sign in to comment.