diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 964baef0..40d8687e 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -38,6 +38,6 @@ jobs: with: platforms: linux/amd64,linux/arm64 registry: ${{ env.REGISTRY }} - context: program/${{ matrix.compiler }} + context: program/${{ matrix.compiler }}/docker push: true tags: ghcr.io/libriscv/${{ matrix.compiler }}_compiler:latest diff --git a/program/cpp/cmake/api b/program/cpp/cmake/api index 8edbb42d..06a5300a 120000 --- a/program/cpp/cmake/api +++ b/program/cpp/cmake/api @@ -1 +1 @@ -../api \ No newline at end of file +../docker/api \ No newline at end of file diff --git a/program/cpp/Dockerfile b/program/cpp/docker/Dockerfile similarity index 100% rename from program/cpp/Dockerfile rename to program/cpp/docker/Dockerfile diff --git a/program/cpp/api/api.cpp b/program/cpp/docker/api/api.cpp similarity index 100% rename from program/cpp/api/api.cpp rename to program/cpp/docker/api/api.cpp diff --git a/program/cpp/api/api.hpp b/program/cpp/docker/api/api.hpp similarity index 100% rename from program/cpp/api/api.hpp rename to program/cpp/docker/api/api.hpp diff --git a/program/cpp/api/api_inline.hpp b/program/cpp/docker/api/api_inline.hpp similarity index 100% rename from program/cpp/api/api_inline.hpp rename to program/cpp/docker/api/api_inline.hpp diff --git a/program/cpp/api/array.cpp b/program/cpp/docker/api/array.cpp similarity index 100% rename from program/cpp/api/array.cpp rename to program/cpp/docker/api/array.cpp diff --git a/program/cpp/api/array.hpp b/program/cpp/docker/api/array.hpp similarity index 100% rename from program/cpp/api/array.hpp rename to program/cpp/docker/api/array.hpp diff --git a/program/cpp/api/basis.cpp b/program/cpp/docker/api/basis.cpp similarity index 100% rename from program/cpp/api/basis.cpp rename to program/cpp/docker/api/basis.cpp diff --git a/program/cpp/api/basis.hpp b/program/cpp/docker/api/basis.hpp similarity index 100% rename from program/cpp/api/basis.hpp rename to program/cpp/docker/api/basis.hpp diff --git a/program/cpp/api/callable.hpp b/program/cpp/docker/api/callable.hpp similarity index 100% rename from program/cpp/api/callable.hpp rename to program/cpp/docker/api/callable.hpp diff --git a/program/cpp/api/canvas_item.hpp b/program/cpp/docker/api/canvas_item.hpp similarity index 100% rename from program/cpp/api/canvas_item.hpp rename to program/cpp/docker/api/canvas_item.hpp diff --git a/program/cpp/api/color.hpp b/program/cpp/docker/api/color.hpp similarity index 100% rename from program/cpp/api/color.hpp rename to program/cpp/docker/api/color.hpp diff --git a/program/cpp/api/dictionary.cpp b/program/cpp/docker/api/dictionary.cpp similarity index 100% rename from program/cpp/api/dictionary.cpp rename to program/cpp/docker/api/dictionary.cpp diff --git a/program/cpp/api/dictionary.hpp b/program/cpp/docker/api/dictionary.hpp similarity index 100% rename from program/cpp/api/dictionary.hpp rename to program/cpp/docker/api/dictionary.hpp diff --git a/program/cpp/api/function.hpp b/program/cpp/docker/api/function.hpp similarity index 100% rename from program/cpp/api/function.hpp rename to program/cpp/docker/api/function.hpp diff --git a/program/cpp/api/native.cpp b/program/cpp/docker/api/native.cpp similarity index 100% rename from program/cpp/api/native.cpp rename to program/cpp/docker/api/native.cpp diff --git a/program/cpp/api/node.cpp b/program/cpp/docker/api/node.cpp similarity index 100% rename from program/cpp/api/node.cpp rename to program/cpp/docker/api/node.cpp diff --git a/program/cpp/api/node.hpp b/program/cpp/docker/api/node.hpp similarity index 100% rename from program/cpp/api/node.hpp rename to program/cpp/docker/api/node.hpp diff --git a/program/cpp/api/node2d.cpp b/program/cpp/docker/api/node2d.cpp similarity index 100% rename from program/cpp/api/node2d.cpp rename to program/cpp/docker/api/node2d.cpp diff --git a/program/cpp/api/node2d.hpp b/program/cpp/docker/api/node2d.hpp similarity index 100% rename from program/cpp/api/node2d.hpp rename to program/cpp/docker/api/node2d.hpp diff --git a/program/cpp/api/node3d.cpp b/program/cpp/docker/api/node3d.cpp similarity index 100% rename from program/cpp/api/node3d.cpp rename to program/cpp/docker/api/node3d.cpp diff --git a/program/cpp/api/node3d.hpp b/program/cpp/docker/api/node3d.hpp similarity index 100% rename from program/cpp/api/node3d.hpp rename to program/cpp/docker/api/node3d.hpp diff --git a/program/cpp/api/object.cpp b/program/cpp/docker/api/object.cpp similarity index 100% rename from program/cpp/api/object.cpp rename to program/cpp/docker/api/object.cpp diff --git a/program/cpp/api/object.hpp b/program/cpp/docker/api/object.hpp similarity index 100% rename from program/cpp/api/object.hpp rename to program/cpp/docker/api/object.hpp diff --git a/program/cpp/api/packed_array.cpp b/program/cpp/docker/api/packed_array.cpp similarity index 100% rename from program/cpp/api/packed_array.cpp rename to program/cpp/docker/api/packed_array.cpp diff --git a/program/cpp/api/packed_array.hpp b/program/cpp/docker/api/packed_array.hpp similarity index 100% rename from program/cpp/api/packed_array.hpp rename to program/cpp/docker/api/packed_array.hpp diff --git a/program/cpp/api/plane.hpp b/program/cpp/docker/api/plane.hpp similarity index 100% rename from program/cpp/api/plane.hpp rename to program/cpp/docker/api/plane.hpp diff --git a/program/cpp/api/quaternion.cpp b/program/cpp/docker/api/quaternion.cpp similarity index 100% rename from program/cpp/api/quaternion.cpp rename to program/cpp/docker/api/quaternion.cpp diff --git a/program/cpp/api/quaternion.hpp b/program/cpp/docker/api/quaternion.hpp similarity index 100% rename from program/cpp/api/quaternion.hpp rename to program/cpp/docker/api/quaternion.hpp diff --git a/program/cpp/api/rect2.hpp b/program/cpp/docker/api/rect2.hpp similarity index 100% rename from program/cpp/api/rect2.hpp rename to program/cpp/docker/api/rect2.hpp diff --git a/program/cpp/api/rect2i.hpp b/program/cpp/docker/api/rect2i.hpp similarity index 100% rename from program/cpp/api/rect2i.hpp rename to program/cpp/docker/api/rect2i.hpp diff --git a/program/cpp/api/rid.hpp b/program/cpp/docker/api/rid.hpp similarity index 100% rename from program/cpp/api/rid.hpp rename to program/cpp/docker/api/rid.hpp diff --git a/program/cpp/api/string.cpp b/program/cpp/docker/api/string.cpp similarity index 100% rename from program/cpp/api/string.cpp rename to program/cpp/docker/api/string.cpp diff --git a/program/cpp/api/string.hpp b/program/cpp/docker/api/string.hpp similarity index 100% rename from program/cpp/api/string.hpp rename to program/cpp/docker/api/string.hpp diff --git a/program/cpp/api/syscalls.h b/program/cpp/docker/api/syscalls.h similarity index 100% rename from program/cpp/api/syscalls.h rename to program/cpp/docker/api/syscalls.h diff --git a/program/cpp/api/syscalls_fwd.hpp b/program/cpp/docker/api/syscalls_fwd.hpp similarity index 100% rename from program/cpp/api/syscalls_fwd.hpp rename to program/cpp/docker/api/syscalls_fwd.hpp diff --git a/program/cpp/api/timer.cpp b/program/cpp/docker/api/timer.cpp similarity index 100% rename from program/cpp/api/timer.cpp rename to program/cpp/docker/api/timer.cpp diff --git a/program/cpp/api/timer.hpp b/program/cpp/docker/api/timer.hpp similarity index 100% rename from program/cpp/api/timer.hpp rename to program/cpp/docker/api/timer.hpp diff --git a/program/cpp/api/transform2d.cpp b/program/cpp/docker/api/transform2d.cpp similarity index 100% rename from program/cpp/api/transform2d.cpp rename to program/cpp/docker/api/transform2d.cpp diff --git a/program/cpp/api/transform2d.hpp b/program/cpp/docker/api/transform2d.hpp similarity index 100% rename from program/cpp/api/transform2d.hpp rename to program/cpp/docker/api/transform2d.hpp diff --git a/program/cpp/api/transform3d.cpp b/program/cpp/docker/api/transform3d.cpp similarity index 100% rename from program/cpp/api/transform3d.cpp rename to program/cpp/docker/api/transform3d.cpp diff --git a/program/cpp/api/transform3d.hpp b/program/cpp/docker/api/transform3d.hpp similarity index 100% rename from program/cpp/api/transform3d.hpp rename to program/cpp/docker/api/transform3d.hpp diff --git a/program/cpp/api/variant.cpp b/program/cpp/docker/api/variant.cpp similarity index 100% rename from program/cpp/api/variant.cpp rename to program/cpp/docker/api/variant.cpp diff --git a/program/cpp/api/variant.hpp b/program/cpp/docker/api/variant.hpp similarity index 100% rename from program/cpp/api/variant.hpp rename to program/cpp/docker/api/variant.hpp diff --git a/program/cpp/api/vector.cpp b/program/cpp/docker/api/vector.cpp similarity index 100% rename from program/cpp/api/vector.cpp rename to program/cpp/docker/api/vector.cpp diff --git a/program/cpp/api/vector.hpp b/program/cpp/docker/api/vector.hpp similarity index 100% rename from program/cpp/api/vector.hpp rename to program/cpp/docker/api/vector.hpp diff --git a/program/cpp/api/vector2.hpp b/program/cpp/docker/api/vector2.hpp similarity index 100% rename from program/cpp/api/vector2.hpp rename to program/cpp/docker/api/vector2.hpp diff --git a/program/cpp/api/vector2i.hpp b/program/cpp/docker/api/vector2i.hpp similarity index 100% rename from program/cpp/api/vector2i.hpp rename to program/cpp/docker/api/vector2i.hpp diff --git a/program/cpp/api/vector3.hpp b/program/cpp/docker/api/vector3.hpp similarity index 100% rename from program/cpp/api/vector3.hpp rename to program/cpp/docker/api/vector3.hpp diff --git a/program/cpp/api/vector3i.hpp b/program/cpp/docker/api/vector3i.hpp similarity index 100% rename from program/cpp/api/vector3i.hpp rename to program/cpp/docker/api/vector3i.hpp diff --git a/program/cpp/api/vector4.hpp b/program/cpp/docker/api/vector4.hpp similarity index 100% rename from program/cpp/api/vector4.hpp rename to program/cpp/docker/api/vector4.hpp diff --git a/program/cpp/api/vector4i.hpp b/program/cpp/docker/api/vector4i.hpp similarity index 100% rename from program/cpp/api/vector4i.hpp rename to program/cpp/docker/api/vector4i.hpp diff --git a/program/cpp/build.sh b/program/cpp/docker/build.sh similarity index 100% rename from program/cpp/build.sh rename to program/cpp/docker/build.sh diff --git a/program/cpp/container_build.sh b/program/cpp/docker/container_build.sh similarity index 100% rename from program/cpp/container_build.sh rename to program/cpp/docker/container_build.sh diff --git a/program/cpp/docker.sh b/program/cpp/docker/docker.sh similarity index 100% rename from program/cpp/docker.sh rename to program/cpp/docker/docker.sh diff --git a/program/cpp/start.sh b/program/cpp/docker/start.sh similarity index 100% rename from program/cpp/start.sh rename to program/cpp/docker/start.sh diff --git a/program/cpp/stop_and_remove.sh b/program/cpp/docker/stop_and_remove.sh similarity index 100% rename from program/cpp/stop_and_remove.sh rename to program/cpp/docker/stop_and_remove.sh diff --git a/program/cpp/test_local_compiler.sh b/program/cpp/docker/test_local_compiler.sh similarity index 100% rename from program/cpp/test_local_compiler.sh rename to program/cpp/docker/test_local_compiler.sh diff --git a/program/rust/.cargo/config.toml b/program/rust/docker/.cargo/config.toml similarity index 77% rename from program/rust/.cargo/config.toml rename to program/rust/docker/.cargo/config.toml index 46348932..788d26aa 100644 --- a/program/rust/.cargo/config.toml +++ b/program/rust/docker/.cargo/config.toml @@ -3,4 +3,4 @@ target = "riscv64gc-unknown-linux-gnu" [target.riscv64gc-unknown-linux-gnu] linker = "riscv64-linux-gnu-gcc-14" -rustflags = ["-C", "target-feature=+crt-static","-Zexport-executable-symbols", "-C", "link_args=-Wl,--wrap=memcpy,--wrap=memmove,--wrap=memset,--wrap=memcmp"] +rustflags = ["-C", "target-feature=+crt-static","-Zexport-executable-symbols", "-C", "link_args=-Wl,--wrap=memcpy,--wrap=memmove,--wrap=memset,--wrap=memcmp,--wrap=strlen,--wrap=strcmp,--wrap=strncmp"] diff --git a/program/rust/.gitignore b/program/rust/docker/.gitignore similarity index 100% rename from program/rust/.gitignore rename to program/rust/docker/.gitignore diff --git a/program/rust/Cargo.toml b/program/rust/docker/Cargo.toml similarity index 100% rename from program/rust/Cargo.toml rename to program/rust/docker/Cargo.toml diff --git a/program/rust/Dockerfile b/program/rust/docker/Dockerfile similarity index 100% rename from program/rust/Dockerfile rename to program/rust/docker/Dockerfile diff --git a/program/rust/build.sh b/program/rust/docker/build.sh similarity index 89% rename from program/rust/build.sh rename to program/rust/docker/build.sh index 8bb55312..f6191448 100755 --- a/program/rust/build.sh +++ b/program/rust/docker/build.sh @@ -34,6 +34,12 @@ if [ -z "$output" ]; then usage fi +if [ "$locally" = true ]; then + cargo +nightly build --release # --color never + cp target/riscv64gc-unknown-linux-gnu/release/rust_program $output + exit +fi + # We are in /usr/src now, so what we need to do is copy the input files to the project directory # The project is in /usr/project cp $@ /usr/project/src/ diff --git a/program/rust/container_build.sh b/program/rust/docker/container_build.sh similarity index 100% rename from program/rust/container_build.sh rename to program/rust/docker/container_build.sh diff --git a/program/rust/src/godot/api.rs b/program/rust/docker/src/godot/api.rs similarity index 100% rename from program/rust/src/godot/api.rs rename to program/rust/docker/src/godot/api.rs diff --git a/program/rust/src/godot/mod.rs b/program/rust/docker/src/godot/mod.rs similarity index 100% rename from program/rust/src/godot/mod.rs rename to program/rust/docker/src/godot/mod.rs diff --git a/program/rust/src/godot/node.rs b/program/rust/docker/src/godot/node.rs similarity index 100% rename from program/rust/src/godot/node.rs rename to program/rust/docker/src/godot/node.rs diff --git a/program/rust/src/godot/sysalloc.rs b/program/rust/docker/src/godot/sysalloc.rs similarity index 76% rename from program/rust/src/godot/sysalloc.rs rename to program/rust/docker/src/godot/sysalloc.rs index 18c8af9c..255830b9 100644 --- a/program/rust/src/godot/sysalloc.rs +++ b/program/rust/docker/src/godot/sysalloc.rs @@ -105,6 +105,55 @@ pub fn __wrap_memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 return result; } +#[no_mangle] +pub fn __wrap_strlen(s: *const u8) -> usize +{ + let result: usize; + unsafe { + asm!("ecall", + in("a0") s, + in("a7") 490, + lateout("a0") result, + options(nostack, readonly) + ); + } + return result; +} + +#[no_mangle] +pub fn __wrap_strcmp(s1: *const u8, s2: *const u8) -> i32 +{ + let result: i32; + unsafe { + asm!("ecall", + in("a0") s1, + in("a1") s2, + in("a2") 4096, // MAX_STRLEN + in("a7") 491, + lateout("a0") result, + options(nostack, readonly) + ); + } + return result; +} + +#[no_mangle] +pub fn __wrap_strncmp(s1: *const u8, s2: *const u8, n: usize) -> i32 +{ + let result: i32; + unsafe { + asm!("ecall", + in("a0") s1, + in("a1") s2, + in("a2") n, + in("a7") 491, + lateout("a0") result, + options(nostack, readonly) + ); + } + return result; +} + #[no_mangle] pub fn fast_exit() -> ! { unsafe { diff --git a/program/rust/src/godot/variant.rs b/program/rust/docker/src/godot/variant.rs similarity index 100% rename from program/rust/src/godot/variant.rs rename to program/rust/docker/src/godot/variant.rs diff --git a/program/rust/start.sh b/program/rust/docker/start.sh similarity index 100% rename from program/rust/start.sh rename to program/rust/docker/start.sh diff --git a/program/rust/stop_and_remove.sh b/program/rust/docker/stop_and_remove.sh similarity index 100% rename from program/rust/stop_and_remove.sh rename to program/rust/docker/stop_and_remove.sh diff --git a/program/rust/project/.cargo/config.toml b/program/rust/project/.cargo/config.toml new file mode 100644 index 00000000..297c0e50 --- /dev/null +++ b/program/rust/project/.cargo/config.toml @@ -0,0 +1,6 @@ +[build] +target = "riscv64gc-unknown-linux-gnu" + +[target.riscv64gc-unknown-linux-gnu] +linker = "riscv64-linux-gnu-gcc-12" +rustflags = ["-C", "target-feature=+crt-static","-Zexport-executable-symbols", "-C", "link_args=-Wl,--wrap=memcpy,--wrap=memmove,--wrap=memset,--wrap=memcmp,--wrap=strlen,--wrap=strcmp,--wrap=strncmp"] diff --git a/program/rust/project/.gitignore b/program/rust/project/.gitignore new file mode 100644 index 00000000..341314b0 --- /dev/null +++ b/program/rust/project/.gitignore @@ -0,0 +1,4 @@ +# Rust ignore +Cargo.lock +target/ +*.elf diff --git a/program/rust/project/Cargo.toml b/program/rust/project/Cargo.toml new file mode 100644 index 00000000..df07b00e --- /dev/null +++ b/program/rust/project/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rust_program" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/program/rust/project/build.sh b/program/rust/project/build.sh new file mode 100755 index 00000000..454c60f3 --- /dev/null +++ b/program/rust/project/build.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -e + +usage() { + echo "Usage: $0 [--api] [-o output] -- [input...]" + echo " --api Instead of compiling, copy the API files to the output." + echo " -o output Compile sources into an output ELF file, including API and inputs." + echo " --debug Compile with debug information." + echo " --version Print the current version of the API." + echo " -v Verbose output." + echo " -- Separate options from input files." + exit 1 +} + +verbose=false +current_version=5 +output="rust.elf" + +while [[ "$#" -gt 0 ]]; do + case $1 in + --api) cp -r /usr/api $1; exit ;; + -o) shift; output="$1"; shift; break ;; + --debug) shift ;; + --version) shift; echo "$current_version"; exit ;; + -v) verbose=true; shift ;; + --) shift; break ;; + *) usage ;; + esac +done + +cargo +nightly build --release # --color never +cp target/riscv64gc-unknown-linux-gnu/release/rust_program $output diff --git a/program/rust/project/src/godot b/program/rust/project/src/godot new file mode 120000 index 00000000..b36cf029 --- /dev/null +++ b/program/rust/project/src/godot @@ -0,0 +1 @@ +../../docker/src/godot \ No newline at end of file diff --git a/program/rust/project/src/main.rs b/program/rust/project/src/main.rs new file mode 100644 index 00000000..58be9914 --- /dev/null +++ b/program/rust/project/src/main.rs @@ -0,0 +1,12 @@ +mod godot; +use godot::variant::*; + +pub fn main() { +} + +#[no_mangle] +pub fn public_function() -> Variant { + print1(&Variant::new_string("Hello from Rust!")); + + return Variant::new_float(3.14); +} diff --git a/program/zig/.gitignore b/program/zig/docker/.gitignore similarity index 100% rename from program/zig/.gitignore rename to program/zig/docker/.gitignore diff --git a/program/zig/Dockerfile b/program/zig/docker/Dockerfile similarity index 100% rename from program/zig/Dockerfile rename to program/zig/docker/Dockerfile diff --git a/program/zig/api/api.zig b/program/zig/docker/api/api.zig similarity index 100% rename from program/zig/api/api.zig rename to program/zig/docker/api/api.zig diff --git a/program/zig/build.sh b/program/zig/docker/build.sh similarity index 100% rename from program/zig/build.sh rename to program/zig/docker/build.sh diff --git a/program/zig/container_build.sh b/program/zig/docker/container_build.sh similarity index 100% rename from program/zig/container_build.sh rename to program/zig/docker/container_build.sh diff --git a/program/zig/start.sh b/program/zig/docker/start.sh similarity index 100% rename from program/zig/start.sh rename to program/zig/docker/start.sh diff --git a/program/zig/stop_and_remove.sh b/program/zig/docker/stop_and_remove.sh similarity index 100% rename from program/zig/stop_and_remove.sh rename to program/zig/docker/stop_and_remove.sh diff --git a/program/zig/project/api b/program/zig/project/api new file mode 120000 index 00000000..06a5300a --- /dev/null +++ b/program/zig/project/api @@ -0,0 +1 @@ +../docker/api \ No newline at end of file diff --git a/src/syscalls.h b/src/syscalls.h index 1a0c81d7..08d03379 120000 --- a/src/syscalls.h +++ b/src/syscalls.h @@ -1 +1 @@ -../program/cpp/api/syscalls.h \ No newline at end of file +../program/cpp/docker/api/syscalls.h \ No newline at end of file