commit 3953ef2bfb3b8eaa5bd2e81d2efdf672ecb6898c Author: CDaut Date: Tue Sep 30 21:06:09 2025 +0200 initial dev setup diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8f390c3 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use_flake \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3dd499a --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.direnv +raytracer/target +vm/esp/efi/boot/bootx64.efi +vm/*.fd +launch_vm.sh \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5850e1a --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1759036355, + "narHash": "sha256-0m27AKv6ka+q270dw48KflE0LwQYrO7Fm4/2//KCVWg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e9f00bd893984bc8ce46c895c3bf7cac95331127", + "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..d7cc375 --- /dev/null +++ b/flake.nix @@ -0,0 +1,88 @@ +{ + description = "Rust development environment for dev with toolchain"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + # Read the file relative to the flake's root + overrides = (builtins.fromTOML (builtins.readFile (self + "/raytracer/rust-toolchain.toml"))); + libPath = with pkgs; lib.makeLibraryPath [ + # load external libraries that you need in your rust project here + ]; + in + { + devShells.default = pkgs.mkShell rec { + nativeBuildInputs = [ pkgs.pkg-config ]; + buildInputs = with pkgs; [ + clang + llvmPackages.bintools + rustup + qemu + OVMF + ]; + + RUSTC_VERSION = overrides.toolchain.channel; + + # https://github.com/rust-lang/rust-bindgen#environment-variables + LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ]; + + shellHook = '' + export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin + export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/ + + # Create VM working directory + mkdir -p ./vm/esp/efi/boot + + # Copy non-secureboot OVMF firmware + writable VARS + cp ${pkgs.OVMF.out.firmware} ./vm/OVMF_CODE.fd + cp ${pkgs.OVMF.out.variables} ./vm/OVMF_VARS.fd + chmod +w ./vm/OVMF_VARS.fd + + # Copy your EFI binary into the ESP + cp raytracer/target/x86_64-unknown-uefi/debug/raytracer.efi ./vm/esp/efi/boot/bootx64.efi + + rm launch_vm.sh && touch launch_vm.sh + echo "/bin/bash" > launch_vm.sh + echo "qemu-system-x86_64 \\" >> launch_vm.sh + echo " -enable-kvm \\" >> launch_vm.sh + echo " -machine q35,accel=kvm \\" >> launch_vm.sh + echo " -drive if=pflash,format=raw,readonly=on,file=./vm/OVMF_CODE.fd \\" >> launch_vm.sh + echo " -drive if=pflash,format=raw,file=./vm/OVMF_VARS.fd \\" >> launch_vm.sh + echo " -drive format=raw,file=fat:rw:./vm/esp" >> launch_vm.sh + + chmod +x launch_vm.sh + + cp raytracer/target/x86_64-unknown-uefi/debug/raytracer.efi vm/esp/efi/boot/bootx64.efi + ''; + + # Add precompiled library to rustc search path + RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [ + # add libraries here (e.g. pkgs.libvmi) + ]); + + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (buildInputs ++ nativeBuildInputs); + + + # Add glibc, clang, glib, and other headers to bindgen search path + BINDGEN_EXTRA_CLANG_ARGS = + # Includes normal include path + (builtins.map (a: ''-I"${a}/include"'') [ + # add dev libraries here (e.g. pkgs.libvmi.dev) + pkgs.glibc.dev + ]) + # Includes with special directory paths + ++ [ + ''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"'' + ''-I"${pkgs.glib.dev}/include/glib-2.0"'' + ''-I${pkgs.glib.out}/lib/glib-2.0/include/'' + ]; + }; + } + ); +} diff --git a/raytracer/Cargo.lock b/raytracer/Cargo.lock new file mode 100644 index 0000000..2246229 --- /dev/null +++ b/raytracer/Cargo.lock @@ -0,0 +1,142 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "bit_field" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6" + +[[package]] +name = "bitflags" +version = "2.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" + +[[package]] +name = "cfg-if" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" + +[[package]] +name = "log" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" + +[[package]] +name = "proc-macro2" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "ptr_meta" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9a0cf95a1196af61d4f1cbdab967179516d9a4a4312af1f31948f8f6224a79" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7347867d0a7e1208d93b46767be83e2b8f978c3dad35f775ac8d8847551d6fe1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "raytracer" +version = "0.1.0" +dependencies = [ + "log", + "uefi", +] + +[[package]] +name = "syn" +version = "2.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "ucs2" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df79298e11f316400c57ec268f3c2c29ac3c4d4777687955cd3d4f3a35ce7eba" +dependencies = [ + "bit_field", +] + +[[package]] +name = "uefi" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7569ceafb898907ff764629bac90ac24ba4203c38c33ef79ee88c74aa35b11" +dependencies = [ + "bitflags", + "cfg-if", + "log", + "ptr_meta", + "ucs2", + "uefi-macros", + "uefi-raw", + "uguid", +] + +[[package]] +name = "uefi-macros" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3dad47b3af8f99116c0f6d4d669c439487d9aaf1c8d9480d686cda6f3a8aa23" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "uefi-raw" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cad96b8baaf1615d3fdd0f03d04a0b487d857c1b51b19dcbfe05e2e3c447b78" +dependencies = [ + "bitflags", + "uguid", +] + +[[package]] +name = "uguid" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab14ea9660d240e7865ce9d54ecdbd1cd9fa5802ae6f4512f093c7907e921533" + +[[package]] +name = "unicode-ident" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" diff --git a/raytracer/Cargo.toml b/raytracer/Cargo.toml new file mode 100644 index 0000000..0236cbb --- /dev/null +++ b/raytracer/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "raytracer" +version = "0.1.0" +edition = "2024" + +[dependencies] +log = "0.4.28" +uefi = { version = "0.35.0", features = ["logger", "panic_handler"] } diff --git a/raytracer/rust-toolchain.toml b/raytracer/rust-toolchain.toml new file mode 100644 index 0000000..1997776 --- /dev/null +++ b/raytracer/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +targets = ["aarch64-unknown-uefi", "i686-unknown-uefi", "x86_64-unknown-uefi"] +channel = "nightly" \ No newline at end of file diff --git a/raytracer/src/main.rs b/raytracer/src/main.rs new file mode 100644 index 0000000..da704a8 --- /dev/null +++ b/raytracer/src/main.rs @@ -0,0 +1,13 @@ +#![no_main] +#![no_std] + +use log::info; +use uefi::prelude::*; + +#[entry] +fn main() -> Status { + uefi::helpers::init().unwrap(); + info!("Hello world!"); + boot::stall(10_000_000); + Status::SUCCESS +} \ No newline at end of file