From cd39fd3a6b016a6e28dca8df4fdfa319cdda2703 Mon Sep 17 00:00:00 2001 From: Julian Stecklina Date: Mon, 21 Nov 2022 11:44:04 +0100 Subject: [PATCH] Initial import of Rust files --- .envrc | 1 + .gitignore | 4 ++ flake.lock | 111 +++++++++++++++++++++++++++++++++++++ flake.nix | 34 ++++++++++++ rust/.cargo/config | 2 + rust/Cargo.lock | 116 +++++++++++++++++++++++++++++++++++++++ rust/Cargo.toml | 9 +++ rust/rust-toolchain.toml | 4 ++ rust/src/main.rs | 12 ++++ 9 files changed, 293 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust/.cargo/config create mode 100644 rust/Cargo.lock create mode 100644 rust/Cargo.toml create mode 100644 rust/rust-toolchain.toml create mode 100644 rust/src/main.rs diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..27a32fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/rust/target +/result +/result-* +/.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..665aedc --- /dev/null +++ b/flake.lock @@ -0,0 +1,111 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1662220400, + "narHash": "sha256-9o2OGQqu4xyLZP9K6kNe1pTHnyPz0Wr3raGYnr9AIgY=", + "owner": "nix-community", + "repo": "naersk", + "rev": "6944160c19cb591eb85bbf9b2f2768a935623ed3", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1669001258, + "narHash": "sha256-fi0hCUCalMwd+RUi6zUBzNb0ShowaJk+o+p8qtF/Iv4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c6e5939c8fa2ab2230baf1378a34746e8db1aed7", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1669001258, + "narHash": "sha256-fi0hCUCalMwd+RUi6zUBzNb0ShowaJk+o+p8qtF/Iv4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c6e5939c8fa2ab2230baf1378a34746e8db1aed7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1665296151, + "narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "14ccaaedd95a488dd7ae142757884d8e125b3363", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1668998422, + "narHash": "sha256-G/BklIplCHZEeDIabaaxqgITdIXtMolRGlwxn9jG2/Q=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "68ab029c93f8f8eed4cf3ce9a89a9fd4504b2d6e", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..651a121 --- /dev/null +++ b/flake.nix @@ -0,0 +1,34 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + naersk.url = "github:nix-community/naersk"; + }; + + outputs = { self, nixpkgs, rust-overlay, naersk }: + let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ + rust-overlay.overlays.default + ]; + }; + + rust = pkgs.rust-bin.fromRustupToolchainFile ./rust/rust-toolchain.toml; + + naersk' = pkgs.callPackage naersk { + cargo = rust; + rustc = rust; + }; + in + { + packages.x86_64-linux.default = naersk'.buildPackage { + src = ./rust; + cargoBuildOptions = old: old ++ [ + "--target x86_64-unknown-uefi" + ]; + }; + }; +} diff --git a/rust/.cargo/config b/rust/.cargo/config new file mode 100644 index 0000000..85d49dc --- /dev/null +++ b/rust/.cargo/config @@ -0,0 +1,2 @@ +[build] +target = "x86_64-unknown-uefi" diff --git a/rust/Cargo.lock b/rust/Cargo.lock new file mode 100644 index 0000000..c2058c5 --- /dev/null +++ b/rust/Cargo.lock @@ -0,0 +1,116 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bit_field" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "lanzaboote" +version = "0.1.0" +dependencies = [ + "uefi", + "uefi-services", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "proc-macro2" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "ucs2" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bad643914094137d475641b6bab89462505316ec2ce70907ad20102d28a79ab8" +dependencies = [ + "bit_field", +] + +[[package]] +name = "uefi" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07b87700863d65dd4841556be3374d8d4f9f8dbb577ad93a39859e70b3b91f35" +dependencies = [ + "bitflags", + "log", + "ucs2", + "uefi-macros", +] + +[[package]] +name = "uefi-macros" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "275f054a1d9fd7e43a2ce91cc24298a87b281117dea8afc120ae95faa0e96b94" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "uefi-services" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74f6e28d165193fb5da5230faec576f0be75c71ce6d171556a2775b3673094b4" +dependencies = [ + "cfg-if", + "log", + "uefi", +] + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 0000000..8e82f61 --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "lanzaboote" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +uefi = { version = "0.18.0", features = ["alloc"] } +uefi-services = "0.15.0" diff --git a/rust/rust-toolchain.toml b/rust/rust-toolchain.toml new file mode 100644 index 0000000..f33bf1a --- /dev/null +++ b/rust/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly-2022-11-21" +components = [ "rust-src" ] +targets = [ "x86_64-unknown-uefi" ] diff --git a/rust/src/main.rs b/rust/src/main.rs new file mode 100644 index 0000000..614326c --- /dev/null +++ b/rust/src/main.rs @@ -0,0 +1,12 @@ +#![no_main] +#![no_std] +#![feature(abi_efiapi)] + +use uefi::prelude::*; + +#[entry] +fn main(_handle: Handle, mut system_table: SystemTable) -> Status { + uefi_services::init(&mut system_table).unwrap(); + + Status::SUCCESS +}