From 71d527c29e4ead996dc9b60cc70d491b6032b5f1 Mon Sep 17 00:00:00 2001 From: Lucas Abel <22837557+uael@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:12:44 +0100 Subject: [PATCH] nix: rust support (#4957) --- backend/windmill-worker/src/rust_executor.rs | 9 +++--- flake.nix | 32 +++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/backend/windmill-worker/src/rust_executor.rs b/backend/windmill-worker/src/rust_executor.rs index 942ac8c16ada4..639adc709aeff 100644 --- a/backend/windmill-worker/src/rust_executor.rs +++ b/backend/windmill-worker/src/rust_executor.rs @@ -15,7 +15,8 @@ use windmill_queue::{append_logs, CanceledBy}; use crate::{ common::{ - check_executor_binary_exists, create_args_and_out_file, get_reserved_variables, read_result, start_child_process, OccupancyMetrics + check_executor_binary_exists, create_args_and_out_file, get_reserved_variables, + read_result, start_child_process, OccupancyMetrics, }, handle_child::handle_child, AuthedClientBackgroundTask, DISABLE_NSJAIL, DISABLE_NUSER, HOME_ENV, NSJAIL_PATH, PATH_ENV, @@ -31,7 +32,7 @@ lazy_static::lazy_static! { static ref HOME_DIR: String = std::env::var("HOME").expect("Could not find the HOME environment variable"); static ref CARGO_HOME: String = std::env::var("CARGO_HOME").unwrap_or_else(|_| { CARGO_HOME_DEFAULT.clone() }); static ref RUSTUP_HOME: String = std::env::var("RUSTUP_HOME").unwrap_or_else(|_| { RUSTUP_HOME_DEFAULT.clone() }); - static ref CARGO_PATH: String = format!("{}/bin/cargo", CARGO_HOME.as_str()); + static ref CARGO_PATH: String = std::env::var("CARGO_PATH").unwrap_or_else(|_| format!("{}/bin/cargo", CARGO_HOME.as_str())); } #[cfg(windows)] @@ -42,8 +43,8 @@ lazy_static::lazy_static! { #[cfg(unix)] lazy_static::lazy_static! { - static ref CARGO_HOME_DEFAULT: String = "/usr/local/cargo".to_string(); - static ref RUSTUP_HOME_DEFAULT: String = "/usr/local/rustup".to_string(); + static ref CARGO_HOME_DEFAULT: String = format!("{}/.cargo", *HOME_DIR); + static ref RUSTUP_HOME_DEFAULT: String = format!("{}/.rustup", *HOME_DIR); } const RUST_OBJECT_STORE_PREFIX: &str = "rustbin/"; diff --git a/flake.nix b/flake.nix index 2f7bf7f176a56..1f25d231a2ede 100644 --- a/flake.nix +++ b/flake.nix @@ -12,11 +12,17 @@ inherit system; overlays = [ (import rust-overlay) ]; }; + rust = pkgs.rust-bin.stable.latest.default.override { + extensions = [ + "rust-src" # for rust-analyzer + "rust-analyzer" + ]; + }; buildInputs = with pkgs; [ openssl openssl.dev libxml2.dev xmlsec.dev libxslt.dev - rust-bin.stable.latest.default nodejs cmake + rust nodejs postgresql - pkg-config + pkg-config cmake ]; PKG_CONFIG_PATH = pkgs.lib.makeSearchPath "lib/pkgconfig" (with pkgs; [ openssl.dev @@ -27,7 +33,7 @@ in { devShell = pkgs.mkShell { buildInputs = buildInputs ++ (with pkgs; [ - git xcaddy sqlx-cli flock rust-analyzer + git xcaddy sqlx-cli flock sccache deno python3 python3Packages.pip go bun uv ]); packages = [ @@ -74,12 +80,14 @@ DATABASE_URL = "postgres://postgres:changeme@127.0.0.1:5432/"; REMOTE = "http://127.0.0.1:8000"; REMOTE_LSP = "http://127.0.0.1:3001"; + RUSTC_WRAPPER = "${pkgs.sccache}/bin/sccache"; DENO_PATH = "${pkgs.deno}/bin/deno"; PYTHON_PATH = "${pkgs.python3}/bin/python3"; GO_PATH = "${pkgs.go}/bin/go"; BUN_PATH = "${pkgs.bun}/bin/bun"; UV_PATH = "${pkgs.uv}/bin/uv"; FLOCK_PATH = "${pkgs.flock}/bin/flock"; + CARGO_PATH = "${rust}/bin/cargo"; }; packages.default = self.packages.${system}.windmill; packages.windmill-client = pkgs.stdenv.mkDerivation { @@ -107,32 +115,26 @@ pname = "windmill"; version = (pkgs.lib.strings.trim (builtins.readFile ./version.txt)); - src = ./.; - nativeBuildInputs = buildInputs ++ [ self.packages.${system}.windmill-client ]; + src = ./backend; + nativeBuildInputs = buildInputs; - cargoRoot = "backend"; cargoLock = { lockFile = ./backend/Cargo.lock; outputHashes = { "php-parser-rs-0.1.3" = "sha256-ZeI3KgUPmtjlRfq6eAYveqt8Ay35gwj6B9iOQRjQa9A="; "progenitor-0.3.0" = "sha256-F6XRZFVIN6/HfcM8yI/PyNke45FL7jbcznIiqj22eIQ="; - "rustpython-ast-0.3.1" = "sha256-q9N+z3F6YICQuUMp3a10OS792tCq0GiSSlkcaLxi3Gs="; - "tiberius-0.12.2" = "sha256-s/S0K3hE+JNCrNVxoSCSs4myLHvukBYTwk2A5vZ7Ae8="; "tinyvector-0.1.0" = "sha256-NYGhofU4rh+2IAM+zwe04YQdXY8Aa4gTmn2V2HtzRfI="; }; }; - buildFeatures = [ ]; + buildFeatures = [ + "embedding" "parquet" "openidconnect" "jemalloc" "deno_core" "license" "http_trigger" "zip" "oauth2" "dind" + "php" "mysql" "mssql" "bigquery" "websocket" "python" "smtp" "csharp" "rust" + ]; doCheck = false; - preBuild = '' - export HOME=$(pwd) - npm config set strict-ssl false - cd backend - ''; inherit PKG_CONFIG_PATH; SQLX_OFFLINE = true; - FRONTEND_BUILD_DIR = "${self.packages.${system}.windmill-client}/build"; RUSTY_V8_ARCHIVE = let version = "130.0.1";