diff --git a/.cargo/config.toml b/.cargo/config.toml index a7abadc..bff29e6 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,2 @@ [build] rustflags = ["--cfg", "tokio_unstable"] -# "-C", "target-cpu=native"] diff --git a/.gitignore b/.gitignore index d80f0e4..5303732 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,8 @@ lcov.info *.profraw *_git2_* /.jj +/.direnv +# Symlink into Nix store after successful `nix build`: +/result +# For personal .envrc files +.envrc \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..7126125 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "esbenp.prettier-vscode", + "jnoortheen.nix-ide", + "rust-lang.rust-analyzer", + "dnut.rewrap-revived" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 490fa22..93ea5ed 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,17 +1,20 @@ { - "files.readonlyInclude": { - "googleapis/**": true, - "target/**": true + "[jsonc]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[typescript]": { - "editor.defaultFormatter": "esbenp.prettier-vscode", - "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.organizeImports": "explicit", - "source.fixAll": "explicit" - } + "source.fixAll": "explicit", + "source.organizeImports": "explicit" + }, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "files.readonlyInclude": { + "googleapis/**": true, + "target/**": true }, - "rust-analyzer.rustfmt.extraArgs": ["+nightly"], + "rewrap.wrappingColumn": 100, "rust-analyzer.cargo.buildScripts.enable": true, - "rewrap.wrappingColumn": 100 + "rust-analyzer.rustfmt.extraArgs": ["+nightly"] } diff --git a/crates/googleapis/include b/crates/googleapis/include index 901fc8e..9bed6f0 160000 --- a/crates/googleapis/include +++ b/crates/googleapis/include @@ -1 +1 @@ -Subproject commit 901fc8ee4257d5d7b0d53ba3494fab53bf1a2a67 +Subproject commit 9bed6f077867e387960082891ec0e1b8bb254a47 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e93369c --- /dev/null +++ b/flake.lock @@ -0,0 +1,143 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "naersk", + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1752475459, + "narHash": "sha256-z6QEu4ZFuHiqdOPbYss4/Q8B0BFhacR8ts6jO/F/aOU=", + "owner": "nix-community", + "repo": "fenix", + "rev": "bf0d6f70f4c9a9cf8845f992105652173f4b617f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "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" + } + }, + "naersk": { + "inputs": { + "fenix": "fenix", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1752689277, + "narHash": "sha256-uldUBFkZe/E7qbvxa3mH1ItrWZyT6w1dBKJQF/3ZSsc=", + "owner": "nix-community", + "repo": "naersk", + "rev": "0e72363d0938b0208d6c646d10649164c43f4d64", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1758690382, + "narHash": "sha256-NY3kSorgqE5LMm1LqNwGne3ZLMF2/ILgLpFr1fS4X3o=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e643668fd71b949c53f8626614b21ff71a07379d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1752428706, + "narHash": "sha256-EJcdxw3aXfP8Ex1Nm3s0awyH9egQvB2Gu+QEnJn2Sfg=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "591e3b7624be97e4443ea7b5542c191311aa141d", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1758854041, + "narHash": "sha256-kZ+24pbf4FiHlYlcvts64BhpxpHkPKIQXBmx1OmBAIo=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "02227ca8c229c968dbb5de95584cfb12b4313104", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "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..0bfd7ce --- /dev/null +++ b/flake.nix @@ -0,0 +1,90 @@ +{ + description = "Google Cloud Firestore emulator with focus on stability"; + + inputs = { + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + naersk = { + url = "github:nix-community/naersk"; # For building rust crates as Nix derivations. + inputs.nixpkgs.follows = "nixpkgs"; + }; + # `self` refers to the copy of this git repository in the Nix Store. By setting + # `self.submodules` to `true`, we ensure the `googleapis` git submodule gets copied into the Nix + # store at the expected path. + self.submodules = true; + }; + + outputs = + { + self, + nixpkgs, + flake-utils, + rust-overlay, + naersk, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + # Initialize the naersk builder to use our specific toolchain: + rust-builder = pkgs.callPackage naersk { + cargo = rust-toolchain; + rustc = rust-toolchain; + }; + # Packages necessary for building the firestore-emulator crate. + buildInputs = with pkgs; [ + openssl + pkg-config + protobuf + ]; + in + { + # Define the development environment with the necessary dependencies and rust toolchain: + devShells.default = pkgs.mkShell { + # Made available in the shell's PATH. + inherit buildInputs; + name = "rust-shell"; + + # Other project dependencies to be made avaible in PATH: + packages = with pkgs; [ + # Nix language server and formatter. + nixd + nixfmt-rfc-style + # Additional project dependencies. + just + cargo-tarpaulin + cargo-nextest + rustup + # Misc. + git + ]; + }; + + # Nix derivation for building the firestore-emulator using Naersk. + # + # `nix build` produces a symlink `./result` that points to the Nix store directory + # containing the built firestore-emulator binary under `./result/bin/firestore-emulator` + # + # Locally, `nix run . -- ARGS` runs the firestore-emulator binary with the provided + # arguments. For example: `nix run . -- --host-port 127.0.0.1:8080` to start the emulator on + # localhost. + # + # You can even run the emulator without manually doing a local checkout of this repository + # with `nix run github:skunkteam/rust-firestore-emulator -- ARGS`. + defaultPackage = rust-builder.buildPackage { + src = self; + # Naersk can't deal with `version = { workspace = true }` for the root package, so extract + # it manually: + version = with builtins; (fromTOML (readFile ./Cargo.toml)).workspace.package.version; + nativeBuildInputs = buildInputs; + }; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..9ea740a --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.90.0" +profile = "default" # Includes components: rustc, rust-std, cargo, rust-docs, rustfmt, and clippy. +components = ["rust-src", "rust-analyzer"] # Additional components.