aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-08-01 12:24:40 +0200
committerHimbeer <himbeer@disroot.org>2024-08-01 12:24:40 +0200
commit78c0100bb21560a9ea2dc2f4176415e5cdf9b3b6 (patch)
tree45f74e02174693d3a186425735bfa2e2025baab8
parent671a17abd90757bbadf02a5d7468c6f6910809ba (diff)
create_process: Use srvre_sys library
-rw-r--r--examples/create_process/build.zig8
-rw-r--r--examples/create_process/build.zig.zon42
-rw-r--r--examples/create_process/src/main.zig39
-rw-r--r--examples/create_process/src/main2.zig22
4 files changed, 27 insertions, 84 deletions
diff --git a/examples/create_process/build.zig b/examples/create_process/build.zig
index a52bd17..c8efa7c 100644
--- a/examples/create_process/build.zig
+++ b/examples/create_process/build.zig
@@ -25,6 +25,11 @@ pub fn build(b: *std.Build) void {
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
+ const srvre_sys = b.dependency("srvre_sys", .{
+ .target = target,
+ .optimize = optimize,
+ });
+
const exe2 = b.addExecutable(.{
.name = "program2",
.root_source_file = b.path("src/main2.zig"),
@@ -38,6 +43,9 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});
+ exe2.root_module.addImport("srvre_sys", srvre_sys.module("srvre_sys"));
+ exe.root_module.addImport("srvre_sys", srvre_sys.module("srvre_sys"));
+
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
// step when running `zig build`).
diff --git a/examples/create_process/build.zig.zon b/examples/create_process/build.zig.zon
index ca5b517..9e5ec94 100644
--- a/examples/create_process/build.zig.zon
+++ b/examples/create_process/build.zig.zon
@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: Zig contributors
+// SPDX-FileCopyrightText: 2024 Himbeer <himbeer@disroot.org>
//
// SPDX-License-Identifier: MIT
@@ -27,44 +28,11 @@
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
- // See `zig fetch --save <url>` for a command-line interface for adding dependencies.
- //.example = .{
- // // When updating this field to a new URL, be sure to delete the corresponding
- // // `hash`, otherwise you are communicating that you expect to find the old hash at
- // // the new URL.
- // .url = "https://example.com/foo.tar.gz",
- //
- // // This is computed from the file contents of the directory of files that is
- // // obtained after fetching `url` and applying the inclusion rules given by
- // // `paths`.
- // //
- // // This field is the source of truth; packages do not come from a `url`; they
- // // come from a `hash`. `url` is just one of many possible mirrors for how to
- // // obtain a package matching this `hash`.
- // //
- // // Uses the [multihash](https://multiformats.io/multihash/) format.
- // .hash = "...",
- //
- // // When this is provided, the package is found in a directory relative to the
- // // build root. In this case the package's hash is irrelevant and therefore not
- // // computed. This field and `url` are mutually exclusive.
- // .path = "foo",
-
- // // When this is set to `true`, a package is declared to be lazily
- // // fetched. This makes the dependency only get fetched if it is
- // // actually used.
- // .lazy = false,
- //},
+ .srvre_sys = .{
+ .url = "https://codeberg.org/Himbeer/srvre_sys/archive/f469f25308cf4e3f6a7f6ccdd9a8f634e10452a2.tar.gz",
+ .hash = "1220ec0ff680d96104969de102f8a9dc85ea3c379297788659def198f04fb7cfd839",
+ },
},
-
- // Specifies the set of files and directories that are included in this package.
- // Only files and directories listed here are included in the `hash` that
- // is computed for this package. Only files listed here will remain on disk
- // when using the zig package manager. As a rule of thumb, one should list
- // files required for compilation plus any license(s).
- // Paths are relative to the build root. Use the empty string (`""`) to refer to
- // the build root itself.
- // A directory listed here means that all files within, recursively, are included.
.paths = .{
"build.zig",
"build.zig.zon",
diff --git a/examples/create_process/src/main.zig b/examples/create_process/src/main.zig
index 28fbca7..a18f61b 100644
--- a/examples/create_process/src/main.zig
+++ b/examples/create_process/src/main.zig
@@ -2,37 +2,16 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-const program2 = @embedFile("program2");
-var buf: [program2.len]u8 = undefined;
-
-export fn _start() void {
- main();
-}
+const srvre_sys = @import("srvre_sys");
+const os = srvre_sys.os;
-pub fn main() void {
- const msg = "Hello from program 1\r\n";
- asm volatile (
- \\ li a7, 100001
- \\ ecall
- :
- : [ptr] "{a0}" (msg.ptr),
- [len] "{a1}" (msg.len),
- : "a7"
- );
+usingnamespace srvre_sys;
- @memcpy(buf[0..], program2);
-
- asm volatile (
- \\ li a7, 100002
- \\ ecall
- :
- : [bytes] "{a0}" (&buf),
- [len] "{a1}" (buf.len),
- : "a7"
- );
+const program2 = @embedFile("program2");
+var buffer: [program2.len]u8 = undefined;
- asm volatile (
- \\ li a7, 100003
- \\ ecall
- ::: "a7");
+pub fn main() void {
+ _ = os.consoleWrite("Hello from program 1\r\n") catch unreachable;
+ @memcpy(buffer[0..], program2);
+ _ = os.launch(@alignCast(buffer[0..])) catch unreachable;
}
diff --git a/examples/create_process/src/main2.zig b/examples/create_process/src/main2.zig
index 89a0255..0099302 100644
--- a/examples/create_process/src/main2.zig
+++ b/examples/create_process/src/main2.zig
@@ -2,23 +2,11 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-export fn _start() void {
- main();
-}
+const srvre_sys = @import("srvre_sys");
+const os = srvre_sys.os;
-pub fn main() void {
- const msg = "Hello from program 2\r\n";
- asm volatile (
- \\ li a7, 100001
- \\ ecall
- :
- : [ptr] "{a0}" (msg.ptr),
- [len] "{a1}" (msg.len),
- : "a7"
- );
+usingnamespace srvre_sys;
- asm volatile (
- \\ li a7, 100003
- \\ ecall
- ::: "a7");
+pub fn main() void {
+ _ = os.consoleWrite("Hello from program 2\r\n") catch unreachable;
}