From 8a033fc3df292845d3f64c9d56b7e8b2b851e1fb Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 29 Sep 2023 20:17:35 +0200 Subject: [PATCH] init --- .cargo/config.toml | 2 ++ .gitignore | 3 ++ Cargo.lock | 16 +++++++++++ Cargo.toml | 18 ++++++++++++ example-user/Cargo.lock | 23 +++++++++++++++ example-user/Cargo.toml | 17 +++++++++++ example-user/src/main.rs | 17 +++++++++++ flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 24 ++++++++++++++++ src/lib.rs | 4 +++ src/sys/mod.rs | 8 ++++++ src/sys/x86_64/mod.rs | 1 + src/sys/x86_64/start.rs | 0 test.sh | 3 ++ 14 files changed, 197 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 example-user/Cargo.lock create mode 100644 example-user/Cargo.toml create mode 100644 example-user/src/main.rs create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 src/lib.rs create mode 100644 src/sys/mod.rs create mode 100644 src/sys/x86_64/mod.rs create mode 100644 src/sys/x86_64/start.rs create mode 100755 test.sh diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..52c9e0e --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[target.x86_64-unknown-linux-gnu] +rustflags = ["-Clink-arg=-nostartfiles", "-Clink-arg=-nostdlib"] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13cb780 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +/example-user/target +/.vscode \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..64a746b --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "libuwuc" +version = "0.1.0" +dependencies = [ + "cfg-if", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..51bd77c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "libuwuc" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[profile.dev] +panic = "abort" + +[profile.release] +panic = "abort" + +[dependencies] +cfg-if = "1.0.0" + +[features] +export_symbols = [] diff --git a/example-user/Cargo.lock b/example-user/Cargo.lock new file mode 100644 index 0000000..719607d --- /dev/null +++ b/example-user/Cargo.lock @@ -0,0 +1,23 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "example-user" +version = "0.1.0" +dependencies = [ + "libuwuc", +] + +[[package]] +name = "libuwuc" +version = "0.1.0" +dependencies = [ + "cfg-if", +] diff --git a/example-user/Cargo.toml b/example-user/Cargo.toml new file mode 100644 index 0000000..cf7d48b --- /dev/null +++ b/example-user/Cargo.toml @@ -0,0 +1,17 @@ +[workspace] + +[package] +name = "example-user" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[profile.dev] +panic = "abort" + +[profile.release] +panic = "abort" + +[dependencies] +libuwuc = { path = "..", features = ["export_symbols"] } \ No newline at end of file diff --git a/example-user/src/main.rs b/example-user/src/main.rs new file mode 100644 index 0000000..145f0af --- /dev/null +++ b/example-user/src/main.rs @@ -0,0 +1,17 @@ +#![cfg_attr(not(test), no_std)] +#![no_main] + +use core::ffi::c_char; + +extern crate libuwuc; + +#[panic_handler] +#[cfg(not(test))] +fn handler(_arg: &core::panic::PanicInfo) -> ! { + loop {} +} + +#[no_mangle] +extern "C" fn main(_argc: i32, _argv: *const *const c_char) -> i32 { + 0 +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..57ae821 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1695830400, + "narHash": "sha256-gToZXQVr0G/1WriO83olnqrLSHF2Jb8BPcmCt497ro0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8a86b98f0ba1c405358f1b71ff8b5e1d317f5db2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7544475 --- /dev/null +++ b/flake.nix @@ -0,0 +1,24 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + rustup + ]; + shellHook = '' + export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin + export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/ + ''; + packages = (with pkgs; [ + ]); + }; + }); +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..04b717c --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,4 @@ +#![no_std] +#![warn(unreachable_pub)] + +mod sys; diff --git a/src/sys/mod.rs b/src/sys/mod.rs new file mode 100644 index 0000000..82b93c0 --- /dev/null +++ b/src/sys/mod.rs @@ -0,0 +1,8 @@ +cfg_if::cfg_if! { + if #[cfg(target_arch = "x86_64")] { + mod x86_64; + pub(crate) use x86_64::*; + } else { + compile_error!("uwuc does not support this target yet!"); + } +} \ No newline at end of file diff --git a/src/sys/x86_64/mod.rs b/src/sys/x86_64/mod.rs new file mode 100644 index 0000000..9b1c790 --- /dev/null +++ b/src/sys/x86_64/mod.rs @@ -0,0 +1 @@ +pub(crate) mod start; \ No newline at end of file diff --git a/src/sys/x86_64/start.rs b/src/sys/x86_64/start.rs new file mode 100644 index 0000000..e69de29 diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..8ab49fe --- /dev/null +++ b/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +cargo run --manifest-path example-user/Cargo.toml