Skip to content

Commit

Permalink
use cargo for rust stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
theverygaming committed Oct 2, 2024
1 parent f52458f commit cdd2f12
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 37 deletions.
23 changes: 22 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
inputs = {
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils }: { } // flake-utils.lib.eachDefaultSystem (system:
outputs = { self, nixpkgs, flake-utils, rust-overlay }: { } // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlays.default ];
};
in
{
devShells = {
Expand Down
4 changes: 1 addition & 3 deletions kernel/rust/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
obj-d += libkernel

obj-$(CONFIG_RUST_SUPPORT) += test.ors
obj-d += rlibk
1 change: 0 additions & 1 deletion kernel/rust/libkernel/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion kernel/rust/libkernel/bindings/mod.rs

This file was deleted.

19 changes: 0 additions & 19 deletions kernel/rust/libkernel/libkernel.rs

This file was deleted.

2 changes: 2 additions & 0 deletions kernel/rust/rlibk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/librlibk.a
7 changes: 7 additions & 0 deletions kernel/rust/rlibk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions kernel/rust/rlibk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "rlibk"
version = "0.1.0"
edition = "2021"

[lib]
name = "rlibk"
crate-type = ["staticlib"]

[dependencies]

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"
9 changes: 9 additions & 0 deletions kernel/rust/rlibk/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lib-$(CONFIG_RUST_SUPPORT) += librlibk.a

# FIXME: figure out the rust target stuff
RUST_TARGET := i686-unknown-linux-gnu

$(objtree)/librlibk.a: $(objtree)/src/**
@#FIXME: get rid of the copy, stupid
@cd $(dir $@) && cargo build --release --target $(RUST_TARGET)
@cp $(dir $@)target/$(RUST_TARGET)/release/librlibk.a $@
5 changes: 5 additions & 0 deletions kernel/rust/rlibk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![no_std]
#![no_main]

mod panic;
mod test;
6 changes: 6 additions & 0 deletions kernel/rust/rlibk/src/panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use core::panic::PanicInfo;

#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::convert::TryFrom;

pub const KP_EMERG: core::ffi::c_int = 0;
pub const KP_ALERT: core::ffi::c_int = 1;
pub const KP_CRIT: core::ffi::c_int = 2;
Expand All @@ -9,3 +11,13 @@ pub const KP_DEBUG: core::ffi::c_int = 7;
extern "C" {
pub fn kprintf(loglevel: core::ffi::c_int, fmt: *const core::ffi::c_char, ...);
}

#[no_mangle]
pub extern "C" fn rust_test(n: i32) -> i32 {
unsafe {
kprintf(KP_INFO, "Hi from Rust :3 :3 number: %u\n".as_bytes().as_ptr() as *const i8, n);
}
let bytes: [u8; 3] = [1, 0, 2];
u16::from_le_bytes(<[u8; 2]>::try_from(&bytes[0..2]).unwrap());
return n;
}
10 changes: 0 additions & 10 deletions kernel/rust/test.rs

This file was deleted.

7 changes: 7 additions & 0 deletions nix-shells/IA-32.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ pkgs.stdenv.mkDerivation {
cross.binutils
cross.gcc
nasm

# Rust stuff
(rust-bin.stable.latest.default.override
{
targets = [ "i686-unknown-linux-gnu" ];
}
)
] ++ common.commonPkgs ++ common.limine ++ common.grub ++ common.fatTools;

shellHook = common.shellHook + ''
Expand Down

0 comments on commit cdd2f12

Please sign in to comment.