Skip to content

Commit

Permalink
Merge pull request #119 from libriscv/zig_script
Browse files Browse the repository at this point in the history
Implement a tiny API for Zig compilation
  • Loading branch information
fwsGonzo authored Sep 16, 2024
2 parents 3f2ea31 + 942e743 commit 6969a79
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
14 changes: 14 additions & 0 deletions program/zig/api/api.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Godot Sandbox Zig API
//
pub const V = union { b: bool, i: i64, f: f64, bytes: [16]u8 };

pub const Variant = struct {
type: i64,
v: V,

pub fn init_int(self: *Variant, int: i64) void {
self.type = 2; // INT
self.v.i = int;
}
};
19 changes: 16 additions & 3 deletions program/zig/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ fi

DIR="$(dirname "${output}")"
FILE="$(basename "${output}")"
time /usr/zig/zig build-exe -O ReleaseSmall -fno-strip -flld -target riscv64-linux $@ --name $FILE
mv $FILE $output
rm -f $FILE.o

cleanup() {
rm -rf /usr/project
}

trap cleanup EXIT

mkdir -p /usr/project/api
cp $@ /usr/project
# Copy the API files to the project directory
cp /usr/api/*.zig /usr/project/api

cd /usr/project
/usr/zig/zig build-exe -O ReleaseSmall -fno-strip -flld -target riscv64-linux *.zig --name $FILE
# Move the output file to the correct location
mv $FILE /usr/src/$output

0 comments on commit 6969a79

Please sign in to comment.