diff --git a/.gitmodules b/.gitmodules index 117572a..03c1557 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "hello"] path = hello url = https://gitea.adnangonzagaci.com/adnangonzaga/hello-rust.git +[submodule "rustlings"] + path = rustlings + url = git@github.com:rust-lang/rustlings.git diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..5c78a69 --- /dev/null +++ b/flake.nix @@ -0,0 +1,88 @@ +{ + description = "Rust Dev environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + }; + + outputs = { self, nixpkgs, flake-utils, rust-overlay }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + + rustVersion = pkgs.rust-bin.stable.latest.default; + + # Packages required for rustlings + rustPackages = with pkgs; [ + # Rust toolchain with extensions + (rustVersion.override { + extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ]; + }) + + # Build essentials + pkg-config + openssl.dev + + # Development tools + rustlings + cargo-edit + cargo-watch + cargo-expand + cargo-audit + + # IDE integration helpers + rust-analyzer + + # Windows compatibility (for cross-compilation) + pkgsCross.mingwW64.buildPackages.gcc + ]; + + # Shell environment variables + shellEnv = { + RUST_SRC_PATH = "${rustVersion}/lib/rustlib/src/rust/library"; + RUSTFLAGS = "-C link-arg=-fuse-ld=gold"; + RUST_BACKTRACE = "1"; + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + }; + + in + { + devShells.default = pkgs.mkShell { + buildInputs = rustPackages; + + shellHook = '' + echo "Rust development environment loaded!" + echo "rustc version: $(rustc --version)" + echo "cargo version: $(cargo --version)" + echo "rustlings version: $(rustlings --version)" + echo "" + echo "You can start rustlings with: rustlings watch" + + mkdir -p .cargo + if [ ! -f .cargo/config.toml ]; then + cat > .cargo/config.toml << EOF +[build] +rustflags = ["-C", "link-arg=-fuse-ld=gold"] + +[target.x86_64-pc-windows-gnu] +linker = "x86_64-w64-mingw32-gcc" +EOF + fi + ''; + + inherit (shellEnv) RUST_SRC_PATH RUSTFLAGS RUST_BACKTRACE PKG_CONFIG_PATH; + }; + } + ); +} diff --git a/rustlings b/rustlings new file mode 160000 index 0000000..7c0d269 --- /dev/null +++ b/rustlings @@ -0,0 +1 @@ +Subproject commit 7c0d269279aaed64d6b8240ed5c1e9f6a981181e