From 777f9034cdcaca4bdc058e6bc379b4fa6cb3fdfb Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Fri, 2 Aug 2024 13:55:48 -0700 Subject: [PATCH 1/4] update rust to 1.80.0 --- DEVELOPING.md | 56 +++++++++++++++++++++++++++++++++++++++++++++ flake.lock | 6 ++--- flake.nix | 6 +++++ rust-toolchain.toml | 2 +- 4 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 DEVELOPING.md diff --git a/DEVELOPING.md b/DEVELOPING.md new file mode 100644 index 00000000..e44d470d --- /dev/null +++ b/DEVELOPING.md @@ -0,0 +1,56 @@ +# Developing + +## Project Maintenance Notes + +### Updating GraphQL Engine for integration tests + +It's important to keep the GraphQL Engine version updated to make sure that the +connector is working with the latest engine version. To update run, + +```sh +$ nix flake lock --update-input graphql-engine-source +``` + +Then commit the changes to `flake.lock` to version control. + +A specific engine version can be specified by editing `flake.lock` instead of +running the above command like this: + +```diff + graphql-engine-source = { +- url = "github:hasura/graphql-engine"; ++ url = "github:hasura/graphql-engine/"; + flake = false; + }; +``` + +### Updating Rust version + +Updating the Rust version used in the Nix build system requires two steps (in +any order): + +- update `rust-overlay` which provides Rust toolchains +- edit `rust-toolchain.toml` to specify the desired toolchain version + +To update `rust-overlay` run, + +```sh +$ nix flake lock --update-input rust-overlay +``` + +If you are using direnv to automatically apply the nix dev environment note that +edits to `rust-toolchain.toml` will not automatically update your environment. +You can make a temporary edit to `flake.nix` (like adding a space somewhere) +which will trigger an update, and then you can revert the change. + +### Updating other project dependencies + +You can update all dependencies declared in `flake.nix` at once by running, + +```sh +$ nix flake update +``` + +This will update `graphql-engine-source` and `rust-overlay` as described above, +and will also update `advisory-db` to get updated security notices for cargo +dependencies, `nixpkgs` to get updates to openssl. diff --git a/flake.lock b/flake.lock index 6192f37f..a0207de9 100644 --- a/flake.lock +++ b/flake.lock @@ -205,11 +205,11 @@ ] }, "locked": { - "lastModified": 1720577957, - "narHash": "sha256-RZuzLdB/8FaXaSzEoWLg3au/mtbuH7MGn2LmXUKT62g=", + "lastModified": 1722565199, + "narHash": "sha256-2eek4vZKsYg8jip2WQWvAOGMMboQ40DIrllpsI6AlU4=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "a434177dfcc53bf8f1f348a3c39bfb336d760286", + "rev": "a9cd2009fb2eeacfea785b45bdbbc33612bba1f1", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 60a9efdd..ad2fb2b1 100644 --- a/flake.nix +++ b/flake.nix @@ -1,18 +1,24 @@ { inputs = { + # nixpkgs provides packages such as mongosh and just, and provides libraries + # used to build the connector like openssl nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; systems.url = "github:nix-systems/default"; + # Nix build system for Rust projects, delegates to cargo crane = { url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; }; + # Allows selecting arbitrary Rust toolchain configurations by editing + # `rust-toolchain.toml` rust-overlay = { url = "github:oxalica/rust-overlay"; inputs.nixpkgs.follows = "nixpkgs"; }; + # Security audit data for Rust projects advisory-db = { url = "github:rustsec/advisory-db"; flake = false; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index d20a64d8..0329f46d 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.77.1" +channel = "1.80.0" profile = "default" # see https://rust-lang.github.io/rustup/concepts/profiles.html components = [] # see https://rust-lang.github.io/rustup/concepts/components.html From 5edab732a801259bde1f75f1dec94f84a756530c Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Fri, 2 Aug 2024 14:22:42 -0700 Subject: [PATCH 2/4] update for api change to crane --- flake.nix | 4 ++-- nix/cargo-boilerplate.nix | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index ad2fb2b1..fa8f28ec 100644 --- a/flake.nix +++ b/flake.nix @@ -69,7 +69,7 @@ # packages or replace packages in that set. overlays = [ (import rust-overlay) - (final: prev: rec { + (final: prev: { # What's the deal with `pkgsBuildHost`? It has to do with # cross-compiling. # @@ -81,7 +81,7 @@ # `pkgsBuildHost` contains copies of all packages compiled to run on # the build system, and to produce outputs for the host system. rustToolchain = final.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; - craneLib = (crane.mkLib final).overrideToolchain rustToolchain; + craneLib = (crane.mkLib final).overrideToolchain (pkgs: pkgs.rustToolchain); # Extend our package set with mongodb-connector, graphql-engine, and # other packages built by this flake to make these packages accessible diff --git a/nix/cargo-boilerplate.nix b/nix/cargo-boilerplate.nix index f032abea..3d5c038a 100644 --- a/nix/cargo-boilerplate.nix +++ b/nix/cargo-boilerplate.nix @@ -53,7 +53,7 @@ let # building for in case we are cross-compiling. In practice this is only # necessary if we are statically linking, and therefore have a `musl` target. # But it doesn't hurt anything to make this override in other cases. - toolchain = rustToolchain.override { targets = [ buildTarget ]; }; + toolchain = pkgs: pkgs.rustToolchain.override { targets = [ buildTarget ]; }; # Converts host system string for use in environment variable names envCase = triple: lib.strings.toUpper (builtins.replaceStrings [ "-" ] [ "_" ] triple); From 20ccd3dea9c0334e7f5cbd457edb9aa421f0cff6 Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Fri, 2 Aug 2024 14:24:15 -0700 Subject: [PATCH 3/4] fix new lint error --- .../src/interface_types/mongo_agent_error.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/mongodb-agent-common/src/interface_types/mongo_agent_error.rs b/crates/mongodb-agent-common/src/interface_types/mongo_agent_error.rs index 40b1dff1..a549ec58 100644 --- a/crates/mongodb-agent-common/src/interface_types/mongo_agent_error.rs +++ b/crates/mongodb-agent-common/src/interface_types/mongo_agent_error.rs @@ -126,13 +126,13 @@ pub enum ErrorResponseType { MutationPermissionCheckFailure, } -impl ToString for ErrorResponseType { - fn to_string(&self) -> String { +impl Display for ErrorResponseType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::UncaughtError => String::from("uncaught-error"), - Self::MutationConstraintViolation => String::from("mutation-constraint-violation"), + Self::UncaughtError => f.write_str("uncaught-error"), + Self::MutationConstraintViolation => f.write_str("mutation-constraint-violation"), Self::MutationPermissionCheckFailure => { - String::from("mutation-permission-check-failure") + f.write_str("mutation-permission-check-failure") } } } From b08e83b4ea285b85510a8a7e24cf24ad64e5cb6d Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Fri, 2 Aug 2024 14:47:41 -0700 Subject: [PATCH 4/4] engine isn't building with 1.80 - use config from that project's toolchain file --- nix/graphql-engine.nix | 4 +++- nix/v3-e2e-testing.nix | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/nix/graphql-engine.nix b/nix/graphql-engine.nix index 141ebf23..3ecd3114 100644 --- a/nix/graphql-engine.nix +++ b/nix/graphql-engine.nix @@ -17,17 +17,19 @@ # The following arguments come from nixpkgs, and are automatically populated # by `callPackage`. , callPackage -, craneLib , git , openssl , pkg-config , protobuf +, rust-bin }: let boilerplate = callPackage ./cargo-boilerplate.nix { }; recursiveMerge = callPackage ./recursiveMerge.nix { }; + craneLib = boilerplate.craneLib.overrideToolchain (pkgs: rust-bin.fromRustupToolchainFile "${src}/rust-toolchain.toml"); + buildArgs = recursiveMerge [ boilerplate.buildArgs { diff --git a/nix/v3-e2e-testing.nix b/nix/v3-e2e-testing.nix index a126b89f..056cd9c4 100644 --- a/nix/v3-e2e-testing.nix +++ b/nix/v3-e2e-testing.nix @@ -17,7 +17,6 @@ # The following arguments come from nixpkgs, and are automatically populated # by `callPackage`. , callPackage -, craneLib , jq , makeWrapper , openssl @@ -28,6 +27,8 @@ let boilerplate = callPackage ./cargo-boilerplate.nix { }; recursiveMerge = callPackage ./recursiveMerge.nix { }; + inherit (boilerplate) craneLib; + buildArgs = recursiveMerge [ boilerplate.buildArgs {