-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.zig
77 lines (65 loc) · 2.72 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addSharedLibrary(.{ .name = "gradle-fileevents", .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"));
lib.addIncludePath(b.path("build/generated/sources/headers/version"));
lib.addIncludePath(b.path("src/main/headers"));
lib.addSystemIncludePath(.{ .cwd_relative = java_include_path });
lib.addSystemIncludePath(.{ .cwd_relative = java_darwin_include_path });
const base_cpp_args = &[_][]const u8{
"--std=c++17",
"-g",
"-pedantic",
"-Wall",
"-Wextra",
"-Wformat=2",
"-Werror",
"-Wno-format-nonliteral",
"-Wno-unguarded-availability-new",
};
const cpp_args = if (target.result.os.tag == .windows)
base_cpp_args ++ &[_][]const u8{
"-DNTDDI_VERSION=NTDDI_WIN10_RS3",
// Need this to actually get our functions in the export table
"-DJNIEXPORT=__declspec(dllexport)",
}
else
base_cpp_args;
// Add source files
lib.addCSourceFiles(.{
.files = &.{
"src/main/cpp/apple_fsnotifier.cpp",
"src/main/cpp/fileevents_version.cpp",
"src/main/cpp/generic_fsnotifier.cpp",
"src/main/cpp/jni_support.cpp",
"src/main/cpp/linux_fsnotifier.cpp",
"src/main/cpp/logging.cpp",
"src/main/cpp/services.cpp",
"src/main/cpp/win_fsnotifier.cpp",
},
.flags = cpp_args,
});
// Link against libc and libstdc++
lib.linkLibC();
lib.linkLibCpp();
if (target.result.os.tag == .macos) {
lib.linkFramework("CoreFoundation");
lib.linkFramework("CoreServices");
lib.addSystemFrameworkPath(.{ .cwd_relative = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" });
}
// lib.verbose_cc = true;
// lib.verbose_link = true;
const install = b.addInstallArtifact(lib, .{
.dest_dir = .{ .override = .{ .custom = "out" } },
});
// Ensure the library is built
const build_step = b.step("build", "Build the file events shared library");
build_step.dependOn(&install.step);
}