From 900a9b8e42c0b278cf1f977dc7b3e0c51f4443fc Mon Sep 17 00:00:00 2001 From: Artur Manuel Date: Tue, 6 Aug 2024 23:45:54 +0100 Subject: [PATCH] feat(rust): initialised cargo --- .envrc | 2 ++ .gitignore | 6 ++++++ Cargo.lock | 7 +++++++ Cargo.toml | 6 ++++++ flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 23 +++++++++++++++++++++++ nix/package.nix | 22 ++++++++++++++++++++++ nix/shell.nix | 25 +++++++++++++++++++++++++ src/main.rs | 3 +++ 9 files changed, 121 insertions(+) create mode 100644 .envrc create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/package.nix create mode 100644 nix/shell.nix create mode 100644 src/main.rs diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..f0d5b48 --- /dev/null +++ b/.envrc @@ -0,0 +1,2 @@ +use flake . --impure +e diff --git a/.gitignore b/.gitignore index e69de29..3b32095 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,6 @@ +.direnv/ +**/*~ + +# Added by cargo + +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..82c423a --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ralsay-rs" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..049ac53 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "ralsay-rs" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..57220ed --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1722813957, + "narHash": "sha256-IAoYyYnED7P8zrBFMnmp7ydaJfwTnwcnqxUElC1I26Y=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "cb9a96f23c491c081b38eab96d22fa958043c9fa", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0cdbe32 --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + description = "ralsay in rust"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs }: + let + systems = [ "x86_64-linux" "aarch64-linux" ]; + forEachSystems = nixpkgs.lib.genAttrs systems; + pkgsForEach = nixpkgs.legacyPackages; + in + { + packages = forEachSystems (system: { + default = pkgsForEach.${system}.callPackage ./nix/package.nix { }; + }); + + devShells = forEachSystems (system: { + default = pkgsForEach.${system}.callPackage ./nix/shell.nix { }; + }); + }; +} diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 0000000..3efc2a6 --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,22 @@ +{ + lib, + rustPlatform, + stdenvAdapters, + llvm, +}: let + toml = (lib.importTOML ../Cargo.toml).package; + pname = toml.name; + inherit (toml) version; +in + rustPlatform.buildRustPackage.override {stdenv = stdenvAdapters.useMoldLinker llvm.stdenv;} { + RUSTFLAGS = "-C link-arg=-fuse-ld=mold"; + + inherit pname version; + + src = builtins.path { + name = "${pname}-${version}"; + path = lib.sources.cleanSource ../.; + }; + + cargoLock.lockFile = ../Cargo.lock; + } diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 0000000..5efe65c --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,25 @@ +{ + mkShell, + rust-analyzer-unwrapped, + rustfmt, + clippy, + cargo, + rustc, + gcc, + rustPlatform, +}: +mkShell { + strictDeps = true; + + nativeBuildInputs = [ + cargo + rustc + gcc + + rust-analyzer-unwrapped + rustfmt + clippy + ]; + + env.RUST_SRC_PATH = "${rustPlatform.rustLibSrc}"; +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}