Current section

Files

Jump to
zigler lib zig templates build.zig.eex
Raw

lib/zig/templates/build.zig.eex

const std = @import("std");
const Builder = std.build.Builder;
<% target = target_struct(@compiler_target, zig_tree) %>
const for_wasm = true;
pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(<%= to_structdef target %>);
//const cflags = [_][]const u8{};
const lib = b.addSharedLibrary(
"<%= @module_spec.module %>",
"<%= @code_file %>",
.{ .versioned = .{.major = <%= @module_spec.version.major %>,
.minor = <%= @module_spec.version.minor %>,
.patch = <%= @module_spec.version.patch %>}});
lib.addSystemIncludeDir("<%= :code.root_dir %>/erts-<%= :erlang.system_info(:version) %>/include");
<%= for dir <- dirs_for(target) do %>
lib.addSystemIncludeDir("<%= Path.join(zig_tree, dir) %>");
<% end %>
<%= for system_include_dir <- @module_spec.system_include_dirs do %>
lib.addSystemIncludeDir("<%= system_include_dir %>");
<% end %>
<%= for include_dir <- @module_spec.include_dirs do %>
lib.addIncludeDir("<%= include_dir %>");
<% end %>
lib.setBuildMode(mode);
lib.setTarget(target);
<%= if @module_spec.link_libc do %>
// use libc if it has been asked for
lib.linkLibC();
<% end %>
<%= if @module_spec.link_libcpp do %>
// use libcpp if it has been asked for
lib.linkLibCpp();
<% end %>
<%= for system_lib <- @module_spec.system_libs do %>
lib.linkSystemLibrary("<%= system_lib %>");
<% end %>
<%= for source <- @module_spec.sources do %>
<%= case source do %>
<% {file, opts} -> %>
lib.addCSourceFile("<%= file %>", &[_][]const u8{<%= Enum.map_join(opts, ", ", &~s("#{&1}")) %>});
<% file -> %>
lib.addCSourceFile("<%= file %>", &[_][]const u8{});
<% end %>
<% end %>
<%= for lib <- @module_spec.libs do %>
<%= cond do %>
<% String.ends_with?(lib, ".so") -> %>
lib.linkSystemLibrary("<%= Path.basename(lib) %>");
<% String.ends_with?(lib, ".dll") -> %>
lib.linkSystemLibrary("<%= Path.basename(lib) %>");
<% String.ends_with?(lib, ".dylib") -> %>
lib.linkSystemLibrary("<%= Path.basename(lib) %>");
<% String.ends_with?(lib, ".a") -> %>
lib.addObjectFile("<%= Path.basename(lib) %>");
<% true -> %>
<% raise "invalid library file" %>
<% end %>
<% end %>
lib.linker_allow_shlib_undefined = true;
// strip_symbols option?
lib.strip = <%= Mix.env() == :prod %>;
// future feature
//
// c files
// for (cfiles) |c_file| {
// lib.addCSourceFile(c_file, &cflags);
// }
lib.install();
}