Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use build.zig for platforms #918

Open
folkertdev opened this issue Jan 19, 2021 · 1 comment
Open

Use build.zig for platforms #918

folkertdev opened this issue Jan 19, 2021 · 1 comment

Comments

@folkertdev
Copy link
Contributor

Currently we manually copy over the str.zig file to any platform written in zig. In the long term we'd want to use some sort of package manager to distribute zig platforms. But in the medium term it would be ideal if we could use a build.zig to reuse the str.zig we use for bitcode generation in the platforms as well, reducing the duplication.

For full context: we can't import the compiler's str.zig directly: zig normally does not allow imports with an arbitrary path.

However, there seems to be no current way to replicate the behavior of zig build-obj with a build.zig file. Our best attempt so far is

const Builder = @import("std").build.Builder;

pub fn build(b: *Builder) void {
    const mode = b.standardReleaseOptions();
    const exe = b.addExecutable("host", null);
    const obj = b.addObject("host", "src/main.zig");

    obj.linkSystemLibrary("c");
    obj.addPackagePath("roc_str", "../../../compiler/builtins/bitcode/src/str.zig");

    exe.addObject(obj);

    exe.setBuildMode(mode);
    exe.setOutputDir(".");

    exe.install();
}

There are two problems

  • we have unresolved externals, so exe.install runs into linker issues
  • obj.install runs into a unreachable in the zig std lib

This issue seems to ask about something related, but the emit_bin flag does not do anything (at least not that I can tell).

@folkertdev
Copy link
Contributor Author

for now we include the str.zig file with the package mechanism:

zig build-obj  --pkg-begin str ../../../compiler/builtins/bitcode/src/str.zig --pkg-end host.zig  --library c -fcompiler-rt

then import as @import("str")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant