Skip to content

Commit

Permalink
Expand the create a project section (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Jul 29, 2022
1 parent beaec86 commit 014da67
Showing 1 changed file with 70 additions and 23 deletions.
93 changes: 70 additions & 23 deletions docs/tutorials/create-a-project.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ sidebar_position: 1
title: Create a Project
---

Once you've [Setup] your development environment, you're ready to create your
first Soroban contract.
Once you've [Setup] your development environment, you're ready to create Soroban
contracts. Creating projects is done using the Rust tool, `cargo`.

[Setup]: setup.mdx
[Setup]: ../getting-started/setup.mdx

Start by creating a new Rust library using the `cargo new` command.
Create a new Rust library using the `cargo new` command.

```sh
cargo new --lib [project-name]
Expand All @@ -18,24 +18,31 @@ Open the `Cargo.toml`, it should look something like this:

```toml title="Cargo.toml"
[package]
name = "first-project"
name = "project-name"
version = "0.1.0"
edition = "2021"
```

## Add `soroban-sdk` Dependency
## Configure the Library Type

Add the following sections to the `Cargo.toml` that will import the `soroban-sdk`.
Add the `crate-type` configuration, required for building contracts.

```toml
[lib]
crate-type = ["cdylib", "rlib"]
```

## Import `soroban-sdk` and Features

Add the following sections to the `Cargo.toml` that will import the
`soroban-sdk`, and configure a set of features explained below.

:::caution
The `soroban-sdk` is in early development. Report issues
[here](https://github.com/stellar/rs-soroban-sdk).
:::

```toml
[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["export"]
export = []
Expand All @@ -45,17 +52,7 @@ testutils = ["soroban-sdk/testutils"]
soroban-sdk = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "32b76650" }

[dev_dependencies]
first-project = { path = ".", features = ["testutils"] }

[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true
project-name = { path = ".", features = ["testutils"] }
```

The `features` list and `dev_dependencies` configure three variations that the
Expand All @@ -70,5 +67,55 @@ not intended to be invoked.
calling the contract in tests. The library itself is added as a `dev_dependencies`
so that whenever its tests are running the `testutils` feature is enabled.

The config for the `release` profile configures the Rust toolchain to produce
smaller contracts.
## Configure the `release` Profile

Configuring the `release` profile to optimize the contract build is critical.
Soroban contracts have a maximum size of 256KB. Rust programs, even small ones,
without these configurations almost always exceed this size.

Add the following to your `Cargo.toml`.

```toml
[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true
```

## Wrapping it Up

The steps below should produce a `Cargo.toml` that looks like so.

```toml title="Cargo.toml"
[package]
name = "project-name"
version = "0.1.0"
edition = "2021"
[features]
default = ["export"]
export = []
testutils = ["soroban-sdk/testutils"]

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
soroban-sdk = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "32b76650" }

[dev_dependencies]
project-name = { path = ".", features = ["testutils"] }
[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true
```

0 comments on commit 014da67

Please sign in to comment.