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

Separate languages into separate docker and project folders #222

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion program/cpp/cmake/api
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions program/rust/build.sh → program/rust/docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions program/rust/project/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 4 additions & 0 deletions program/rust/project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Rust ignore
Cargo.lock
target/
*.elf
8 changes: 8 additions & 0 deletions program/rust/project/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
32 changes: 32 additions & 0 deletions program/rust/project/build.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions program/rust/project/src/godot
12 changes: 12 additions & 0 deletions program/rust/project/src/main.rs
Original file line number Diff line number Diff line change
@@ -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);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions program/zig/project/api
2 changes: 1 addition & 1 deletion src/syscalls.h
Loading