Turborepo

Multi-language support

Turborepo is built on the conventions of the JavaScript ecosystem to find scripts and tasks to execute - but it doesn't care what those scripts do. Following the guidance for specifying a package in a JavaScript workspace, you can add any other language or toolchain to Turborepo.

As an example, you may have a Rust project in the ./cli directory in your repository. To add this directory as a package to your JavaScript package manager's workspace, add the directory to the workspace definition:

./package.json
{
  "workspaces": [
    "apps/*"
    "packages/*",
    "cli"
  ]
}
npm workspace documentation

Then, add a package.json to the directory:

./cli/package.json
{
  "name": "@repo/rust-cli",
  "scripts": {
    "build": "cargo build"
  }
}

Now, when you use turbo build, the "build" script in ./cli/package.json will be included into the tasks that turbo runs.

Caching build artifacts

Ensure that the outputs for your builds are being cached with the outputs key in turbo.json. In the case of a Rust CLI being compiled with cargo, a release build would be created in the target/release directory and we can cache it using:

./turbo.json
{
  "tasks": {
    "build": {
      "outputs": ["target/release/**"] 
    }
  }
}

Creating dependency relationships

Because the directory is now a part of the package manager's workspace, you can create dependencies exactly the same as you do for your JavaScript packages.

For instance, if you wanted to make sure that the rust-cli "package" from above is built before your web application, install it into the dependencies for the web application:

./web/package.json
{
  "devDependencies": {
+   "@repo/rust-cli": "*"
  }
}

Given a turbo.json with a build task like:

./turbo.json
{
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": ["dist/**", "target/release/**"]
    }
  }
}

turbo build will first create the artifacts for the Rust CLI and then build the web application.

hours

Total Compute Saved
Get started with
Remote Caching →

On this page