@@ -9,6 +9,7 @@ pub fn build(b: *std.Build) anyerror!void {
9
9
const target_opt = b .standardTargetOptions (.{});
10
10
const optimize_opt = b .standardOptimizeOption (.{});
11
11
const disable_aro_opt = b .option (bool , "disable-aro" , "Disable Aro C compiler integration" ) orelse false ;
12
+ const disable_ffi_opt = b .option (bool , "disable-ffi" , "Disable libffi interpreter integration" ) orelse false ;
12
13
13
14
// TODO: https://github.com/ziglang/zig/issues/15373
14
15
const pandoc_prog = b .findProgram (&.{"pandoc" }, &.{}) catch @panic ("Could not locate `pandoc` program." );
@@ -21,6 +22,8 @@ pub fn build(b: *std.Build) anyerror!void {
21
22
const install_vscode_step = b .step ("install-vscode" , "Install VS Code extension" );
22
23
const uninstall_vscode_step = b .step ("uninstall-vscode" , "Uninstall VS Code extension" );
23
24
25
+ const target = target_opt .result ;
26
+
24
27
const npm_install_doc_step = b .addSystemCommand (&.{ "npm" , "install" });
25
28
npm_install_doc_step .setName ("npm install" );
26
29
@@ -111,6 +114,31 @@ pub fn build(b: *std.Build) anyerror!void {
111
114
graf_mod .addImport ("aro" , aro_dep .module ("aro" ));
112
115
}
113
116
117
+ // TODO: libffi should be a lazy dependency, but this causes HTTP problems on macOS.
118
+ const ffi_dep = b .dependency ("ffi" , .{
119
+ .target = target_opt ,
120
+ .optimize = optimize_opt ,
121
+ });
122
+
123
+ if (! disable_ffi_opt ) {
124
+ if (b .systemIntegrationOption ("ffi" , .{})) {
125
+ graf_mod .linkSystemLibrary ("ffi" , .{});
126
+ } else if (switch (target .cpu .arch ) {
127
+ // libffi only supports MSVC for Windows on Arm.
128
+ .aarch64 , .aarch64_be , .aarch64_32 = > target .os .tag != .windows ,
129
+ // TODO: https://github.com/ziglang/zig/issues/10411
130
+ .arm , .armeb = > target .getFloatAbi () != .soft and target .os .tag != .windows ,
131
+ // TODO: https://github.com/llvm/llvm-project/issues/58377
132
+ .mips , .mipsel , .mips64 , .mips64el = > false ,
133
+ // TODO: https://github.com/ziglang/zig/issues/19107
134
+ .riscv32 , .riscv64 = > false ,
135
+ // TODO: https://github.com/ziglang/zig/issues/20361
136
+ else = > ! target .isDarwin (),
137
+ }) {
138
+ graf_mod .linkLibrary (ffi_dep .artifact ("ffi" ));
139
+ }
140
+ }
141
+
114
142
b .installDirectory (.{
115
143
.source_dir = aro_dep .path ("include" ),
116
144
.install_dir = .header ,
@@ -121,7 +149,7 @@ pub fn build(b: *std.Build) anyerror!void {
121
149
122
150
const stlib_step = b .addStaticLibrary (.{
123
151
// Avoid name clash with the DLL import library on Windows.
124
- .name = if (target_opt . result .os .tag == .windows ) "libgraf" else "graf" ,
152
+ .name = if (target .os .tag == .windows ) "libgraf" else "graf" ,
125
153
.root_source_file = b .path (b .pathJoin (&.{ "lib" , "c.zig" })),
126
154
.target = target_opt ,
127
155
.optimize = optimize_opt ,
@@ -187,7 +215,7 @@ pub fn build(b: *std.Build) anyerror!void {
187
215
});
188
216
189
217
// PIE is off by default; enable it for hardening purposes.
190
- exe_step .pie = switch (target_opt . result .cpu .arch ) {
218
+ exe_step .pie = switch (target .cpu .arch ) {
191
219
// TODO: https://github.com/ziglang/zig/issues/20305
192
220
.mips , .mipsel , .mips64 , .mips64el = > false ,
193
221
.powerpc , .powerpcle , .powerpc64 , .powerpc64le = > false ,
0 commit comments