0.0.16 • Published 3 years ago

@svelte-up/projen-rust-project v0.0.16

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

An very experimental plugin (project generator) for projen that aims to make spinning up and maintaining cargo-based rustlang projects easy and predicatable.

Getting Started

To create a new project, run the following command and follow the instructions.

$ mkdir my-project
$ cd my-project
$ git init
$ npx projen new --from @svelte-up/projen-rust-project

Use npx projen new --from @svelte-up/projen-rust-project --help to view a list of command line switches that allow you to specify most project options during bootstrapping.

The new command will create a .projenrc.js file which looks like the below for projen-rust-project projects.

const { RustProjectBase } = require("@svelte-up/projen-rust-project");

const project = new RustProjectBase({
  defaultReleaseBranch: "main",
  devDeps: ["@svelte-up/projen-rust-project"],
  name: "projen-rust-project-example",
});

project.synth();

This configuration instantiates your project with minimal setup, and synthesizes default project files.

Next Steps

Once your project is created, you can configure the project by editing .projenrc.js and re-running npx projen to re-synthesize.

Customize the Generated Cargo Manifest

interface RustProjectBaseOptions extends TypeScriptProjectOptions {
  readonly manifest: CargoManifest;
  readonly target: string;
}

At present, the structure and configuration of your project is primarily controlled via the manifest property on the RustProjectBaseOptions interface. Here, you control how your Cargo.toml file is generated.

For example, the .projenrc.js configuration below generates the subsequent Cargo.toml:

.projenrc.js

// .projenrc.js

const project = new RustProjectBase({
  defaultReleaseBranch: "main",
  devDeps: ["@getsvelteup/projen-rust-project"],
  name: "projen-test-2",
  manifest: {
    package: {
      name: "projen-test",
      version: "0.0.1",
      edition: "2021",
      authors: ["Michael Edelman <michael@svelteup.io>"],
      license: "Apache-2.0",
    },
    dependencies: {
      lambda_http: "0.4.1",
      tokio: { version: "1", features: ["full"] },
      serde_json: "1.0.64",
      simple_logger: "1.13.0",
      log: "0.4.14",
    },
    devDependencies: {
      pretty_assertions: "1.0.0",
    },
    profile: {
      dev: {
        lto: false,
      },
      release: {
        lto: true,
        panic: "abort",
      },
    },
  },
});

Cargo.toml

# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".

[package]
name = "projen-test"
version = "0.0.1"
edition = "2021"
authors = [ "Michael Edelman <michael@svelteup.io>" ]
license = "Apache-2.0"

[dependencies]
lambda_http = "0.4.1"
serde_json = "1.0.64"
simple_logger = "1.13.0"
log = "0.4.14"

  [dependencies.tokio]
  version = "1"
  features = [ "full" ]

[profile.dev]
lto = false
debug = 1
incremental = true

[profile.release]
lto = true
debug = false
incremental = true
panic = "abort"

[dev-dependencies]
pretty_assertions = "1.0.0"

Cargo.toml support is pretty robust; however, some features and or settings are currently in development. For a full overview see the API Reference section below.

Add Additional Binaries, Tests, Examples, and Benches

Binaries, tests, examples, and benches can be incldued directly via the manifest configuration above. Alternatively, you can use the various helper methods on your project to do the same. For every binary, test, example, or bench included, the project will automatically stub out the item at its expected location and modify the Cargo.toml file appropriately.

project.addBinary("bootstrap", {
  name: "bootstrap",
  path: "src/bin/bootstrap.rs",
});

project.addBinary("another", {
  name: "another",
  path: "src/bin/another.rs",
  doc: false,
  edition: "2018",
});

Build, Test, Etc.

Projen rust project also generates a package.json file with various execution scripts for interacting with your project based on your custom configuration defined above. For example, adding the two binaries above will result in the creation of the following:

{
  "scripts": {
    "build": "npx npm-run-all -p build:*",
    "build:bootstrap": "cargo build --release  --bin bootstrap",
    "build:another": "cargo build --release  --bin another"
  }
}

Thereafter, you can build individual binaries by running yarn build:<binary-name> or build all of them simply by running yarn build.

API Reference

See API Reference for API details.

Contributions

Contributions of all kinds are welcome! For a quick start, check out a development environment.

$ git clone git@github.com:GetSvelteUp/projen-rust-project
$ cd projen-rust-project
$ yarn
$ yarn watch

License

Distributed under the Apache-2.0 license.