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

feat(zig-sdk): Implement Host Functions #249

Merged
merged 13 commits into from
Feb 12, 2023
Merged

feat(zig-sdk): Implement Host Functions #249

merged 13 commits into from
Feb 12, 2023

Conversation

usdogu
Copy link
Contributor

@usdogu usdogu commented Feb 4, 2023

There are some breaking changes:

@usdogu usdogu marked this pull request as draft February 4, 2023 18:07
@usdogu usdogu marked this pull request as ready for review February 4, 2023 18:51
@usdogu
Copy link
Contributor Author

usdogu commented Feb 4, 2023

It should be done now, the check randomly fails because of threads

@nilslice
Copy link
Member

nilslice commented Feb 5, 2023

Awesome, @usdogu - thank you!

I will test this out and get back to you asap.

@nilslice nilslice changed the title feat(zig)!: Implement Host Functions feat(zig-sdk): Implement Host Functions Feb 8, 2023
@nilslice
Copy link
Member

nilslice commented Feb 8, 2023

I have TODOs to update the extism.org docs with the latest build.zig configuration from this PR.

@nilslice
Copy link
Member

It seems (based on this comment) that there was just a minor missing step to ensure the Thread resources were cleaned up.

detach could also probably be used here to more closely demonstrate the effect of assigning the Thread to _ as previously done. If CI passes with this change, it's good enough for me ;)

Copy link
Member

@nilslice nilslice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 awesome work, @usdogu!

@nilslice nilslice merged commit f0f53c7 into extism:main Feb 12, 2023
@usdogu usdogu deleted the implement-zig-host-functions branch February 12, 2023 19:38
@nilslice
Copy link
Member

Updated docs: https://extism.org/docs/integrate-into-your-codebase/zig-host-sdk/

@usdogu, if you have some time to review, please let me know if you see anything incorrect there. Thanks!

@usdogu
Copy link
Contributor Author

usdogu commented Feb 12, 2023

@nilslice, In build.zig

--- old.zig     2023-02-13 00:08:40.411043737 +0300
+++ build.zig   2023-02-13 00:10:27.331042426 +0300
@@ -4,21 +4,21 @@
     const target = b.standardTargetOptions(.{});
     const optimize = b.standardOptimizeOption(.{});
     const exe = b.addExecutable(.{
-        .root_source_file = "src/main.zig",
+        .root_source_file = .{ .path = "src/main.zig" },
         .target = target,
         .optimize = optimize,
     });

     // Add the `extism` library from the cloned repository
-    exe.addAnonymousModule("extism", .{ .source_file = .{ .path = "src/main.zig" } });
+    exe.addAnonymousModule("extism", .{ .source_file = .{ .path = "libs/extism/zig/src/main.zig" } });
     exe.linkLibC();

@@ -30,9 +30,11 @@
     const run_step = b.step("run", "Run the app");
     run_step.dependOn(&run_cmd.step);

-    const exe_tests = b.addTest("src/main.zig");
-    exe_tests.setTarget(target);
-    exe_tests.setBuildMode(mode);
+    var exe_tests = b.addTest(.{
+       .root_source_file = .{ .path = "src/main.zig" },
+       .target = target,
+       .optimize = optimize
+    });

     const test_step = b.step("test", "Run unit tests");
     test_step.dependOn(&exe_tests.step);

@nilslice
Copy link
Member

Updated -- thank you for catching the path issue, and fixing the test config! I'm always learning more about Zig :)

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

Successfully merging this pull request may close these issues.

None yet

2 participants