From a612298b910e48e54a07ae5c6147339785ac820b Mon Sep 17 00:00:00 2001 From: Wen-jing-Ye <142137743+Wen-jing-Ye@users.noreply.github.com> Date: Wed, 29 May 2024 17:48:52 +0930 Subject: [PATCH 1/2] Update README.md with a more detailed import instruction --- README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 67e0791..e39697b 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,23 @@ Reference-counted pointers for Zig inspired by Rust's [`Rc`](https://doc.rust-la ## How to use -To use `zigrc`, import the `src/main.zig` file into your project, or [add it as a module](https://zig.guide/build-system/modules) on your build file. - +To use `zigrc`, import the `src/root.zig` file into your project, or add it as a module by running command shown below in your project directory. +```console +zig fetch "https://github.com/Aandreba/zigrc/archive/refs/tags/0.4.0.tar.gz" --save=zigrc +``` +Then import it in your build file (`build.zig`): +```zig +pub fn build(b: *std.Build) void { +// ... + const zigrc_dep = b.dependency("zigrc", .{}); + const zigrc_mod = &zigrc_dep.artifact("zig-rc").root_module; + exe.root_module.addImport("zigrc", zigrc_mod); + lib.root_module.addImport("zigrc", zigrc_mod); + exe_unit_tests.root_module.addImport("zigrc", zigrc_mod); + lib_unit_tests.root_module.addImport("zigrc", zigrc_mod); +// ... +} +``` ## Example ```zig From a92ce554c416e5dd334dc2357f0021bc29421f34 Mon Sep 17 00:00:00 2001 From: Aandreba Date: Wed, 29 May 2024 11:15:40 +0200 Subject: [PATCH 2/2] modified the example to be more verbose --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e39697b..9fd3e8f 100644 --- a/README.md +++ b/README.md @@ -8,22 +8,33 @@ Reference-counted pointers for Zig inspired by Rust's [`Rc`](https://doc.rust-la ## How to use To use `zigrc`, import the `src/root.zig` file into your project, or add it as a module by running command shown below in your project directory. + ```console +# you can fetch via archive zig fetch "https://github.com/Aandreba/zigrc/archive/refs/tags/0.4.0.tar.gz" --save=zigrc + +# or fetch via git +zig fetch "git+https://github.com/Aandreba/zigrc#" --save=zigrc ``` + Then import it in your build file (`build.zig`): ```zig pub fn build(b: *std.Build) void { // ... + // Import the dependency const zigrc_dep = b.dependency("zigrc", .{}); + + // Extract the module const zigrc_mod = &zigrc_dep.artifact("zig-rc").root_module; + + // Add the dependency as an import to your library/executable exe.root_module.addImport("zigrc", zigrc_mod); lib.root_module.addImport("zigrc", zigrc_mod); - exe_unit_tests.root_module.addImport("zigrc", zigrc_mod); - lib_unit_tests.root_module.addImport("zigrc", zigrc_mod); + unit_tests.root_module.addImport("zigrc", zigrc_mod); // ... } ``` + ## Example ```zig