cuprate-hinto-janai/misc/ENVIRONMENT-ADIVE.md
Someone Else 47238fbef3
Adding development environment advices (#49)
* added ws dev advices

* removed nightly rustfmt
2024-02-02 23:37:15 +00:00

2.7 KiB

Development environment advice

This documentation contain advice for setting up the development environment.

Cuprate is a rust project, and therefore inherit the use of the default of LSP plugin Rust-analyzer. Rust-analyzer is well conceived but can be slow on big project such as Cuprate.

Here are following suggested configurations from Polkadot-SDK's documentation:

Rust-analyzer's VSCode plugin:

{
  // Use a separate target dir for Rust Analyzer. Helpful if you want to use Rust
  // Analyzer and cargo on the command line at the same time.
  "rust-analyzer.rust.analyzerTargetDir": "target/vscode-rust-analyzer",
  // Improve stability
  "rust-analyzer.server.extraEnv": {
    "CHALK_OVERFLOW_DEPTH": "100000000",
    "CHALK_SOLVER_MAX_SIZE": "10000000"
  },
  // Check feature-gated code
  "rust-analyzer.cargo.features": "all",
  "rust-analyzer.cargo.extraEnv": {
    // Skip building WASM, there is never need for it here
    "SKIP_WASM_BUILD": "1"
  },
  // Don't expand some problematic proc_macros
  "rust-analyzer.procMacro.ignored": {
    "async-trait": ["async_trait"],
    "napi-derive": ["napi"],
    "async-recursion": ["async_recursion"],
    "async-std": ["async_std"]
  },
}

Rust-analyzer's Neovim LUA plugin:

["rust-analyzer"] = {
  rust = {
    # Use a separate target dir for Rust Analyzer. Helpful if you want to use Rust
    # Analyzer and cargo on the command line at the same time.
    analyzerTargetDir = "target/nvim-rust-analyzer",
  },
  server = {
    # Improve stability
    extraEnv = {
      ["CHALK_OVERFLOW_DEPTH"] = "100000000",
      ["CHALK_SOLVER_MAX_SIZE"] = "100000000",
    },
  },
  cargo = {
    # Check feature-gated code
    features = "all",
    extraEnv = {
      # Skip building WASM, there is never need for it here
      ["SKIP_WASM_BUILD"] = "1",
    },
  },
  procMacro = {
    # Don't expand some problematic proc_macros
    ignored = {
      ["async-trait"] = { "async_trait" },
      ["napi-derive"] = { "napi" },
      ["async-recursion"] = { "async_recursion" },
      ["async-std"] = { "async_std" },
    },
  },
},

Usage of cargo -p

Prefer to use cargo -p while possible, as any cargo in workspace mode will check and build dependencies of every crates in the repository.

On Rust-analyzer's VSCode plugin, you can add the following configuration if you're focused on one specific crate:

"rust-analyzer.check.extraArgs": [
	"-p <CRATE_NAME>"
],

Alternative IDE

If you still deal with lags on VSCode or Neovim, you could try the following IDE:

  • RustRover: It have been reported to have excellent performance at managing huge workspace. It use its own fine-tuned plugins by jetbrains.
  • Zed: Rust-written IDE focused on performance. Still in beta and macOS only.