-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed as not planned
Description
Zig Version
0.14.0-dev.144+a31fe8aa3
Steps to Reproduce and Observed Behavior
In the following example, a Linux executable is allowed to import a module targeting WASI.
// build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const foreign = b.addModule("foreign", .{
.root_source_file = b.path("src/foreign.zig"),
.target = b.resolveTargetQuery(.{ .os_tag = .wasi }),
});
const exe = b.addExecutable(.{
.name = "main",
.root_source_file = b.path("src/main.zig"),
.target = b.standardTargetOptions(.{}),
});
exe.root_module.addImport("foreign", foreign);
const run_step = b.step("run", "Run the executable");
run_step.dependOn(&b.addRunArtifact(exe).step);
}// src/foreign.zig
pub const os = @import("builtin").os;// src/main.zig
const std = @import("std");
pub fn main() void {
std.debug.print("builtin os: {}\n", .{ @import("builtin").os.tag });
std.debug.print("foreign os: {}\n", .{ @import("foreign").os.tag });
}$ zig-linux-x86_64-0.14.0-dev.144+a31fe8aa3/zig build run
builtin os: Target.Os.Tag.linux
foreign os: Target.Os.Tag.wasi
Expected Behavior
I see two problems with this behavior:
- The imported module cannot observe the actual compilation options because
builtindoes not behave as one might expect. - The intended compilation options of the imported module are ignored. So the
Module.CreateOptionsargument ofaddModuledoes not do what one might expect.
I think the build system should do one of the following:
- ensure that any overrides of compilation options are reflected in
builtin, or - refuse to import modules with different compilation options. For instance, refuse to import if anything in
builtinwill differ between the importing and the imported modules.
I don't know which is better, partly because I don't understand why Module was designed to carry compilation options in the first place.
Metadata
Metadata
Assignees
Labels
No labels