Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profile.release to Cargo.toml generated by cargo component new #289

Merged

Conversation

calvinrp
Copy link
Collaborator

@calvinrp calvinrp commented May 6, 2024

This adds a default [profile.release]:

[profile.release]
codegen-units = 1
opt-level = "s"
debug = false
strip = true
lto = true

The cargo component build --release of the cargo component new --lib output goes from 1.6 MB -> 52 KB.

@calvinrp calvinrp changed the title Add release.profile to Cargo.toml generated by cargo component new Add profile.release to Cargo.toml generated by cargo component new May 6, 2024
@calvinrp
Copy link
Collaborator Author

calvinrp commented May 7, 2024

@fibonacci1729 @macovedj can you merge? I don't have permissions

@fibonacci1729 fibonacci1729 merged commit e65e553 into bytecodealliance:main May 7, 2024
6 checks passed
@calvinrp calvinrp deleted the new-updated-release-profile branch May 7, 2024 18:51
mergify bot referenced this pull request in andrzejressel/pulumi-gestalt Jun 30, 2024
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cargo-component](https://togithub.com/bytecodealliance/cargo-component) | minor | `0.10.1` -> `0.13.0` |

---

### Release Notes

<details>
<summary>bytecodealliance/cargo-component (cargo-component)</summary>

### [`v0.13.2`](https://togithub.com/bytecodealliance/cargo-component/releases/tag/v0.13.2)

[Compare Source](https://togithub.com/bytecodealliance/cargo-component/compare/v0.13.1...v0.13.2)

#### What's Changed

-   Add `cargo component serve` subcommand by [@&#8203;primoly](https://togithub.com/primoly) in [https://github.com/bytecodealliance/cargo-component/pull/305](https://togithub.com/bytecodealliance/cargo-component/pull/305)
-   added wasmtime wasi args for `cargo component serve` by [@&#8203;calvinrp](https://togithub.com/calvinrp) in [https://github.com/bytecodealliance/cargo-component/pull/308](https://togithub.com/bytecodealliance/cargo-component/pull/308)

#### New Contributors

-   [@&#8203;primoly](https://togithub.com/primoly) made their first contribution in [https://github.com/bytecodealliance/cargo-component/pull/305](https://togithub.com/bytecodealliance/cargo-component/pull/305)

**Full Changelog**: bytecodealliance/cargo-component@v0.13.1...v0.13.2

### [`v0.13.1`](https://togithub.com/bytecodealliance/cargo-component/releases/tag/v0.13.1)

[Compare Source](https://togithub.com/bytecodealliance/cargo-component/compare/v0.13.0...v0.13.1)

#### What's Changed

-   More `cargo component new` generator fixes by [@&#8203;calvinrp](https://togithub.com/calvinrp) in [https://github.com/bytecodealliance/cargo-component/pull/304](https://togithub.com/bytecodealliance/cargo-component/pull/304)

**Full Changelog**: bytecodealliance/cargo-component@v0.13.0...v0.13.1

### [`v0.13.0`](https://togithub.com/bytecodealliance/cargo-component/releases/tag/v0.13.0)

[Compare Source](https://togithub.com/bytecodealliance/cargo-component/compare/v0.12.0...v0.13.0)

#### What's Changed

-   set dev version by [@&#8203;calvinrp](https://togithub.com/calvinrp) in [https://github.com/bytecodealliance/cargo-component/pull/297](https://togithub.com/bytecodealliance/cargo-component/pull/297)
-   Bug fixes for targeting a world with resource borrows by [@&#8203;calvinrp](https://togithub.com/calvinrp) in [https://github.com/bytecodealliance/cargo-component/pull/300](https://togithub.com/bytecodealliance/cargo-component/pull/300)

**Full Changelog**: bytecodealliance/cargo-component@v0.12.0...v0.13.0

### [`v0.12.0`](https://togithub.com/bytecodealliance/cargo-component/releases/tag/v0.12.0)

[Compare Source](https://togithub.com/bytecodealliance/cargo-component/compare/v0.11.0...v0.12.0)

#### What's Changed

-   add support for missing settings from wit-bindgen by [@&#8203;sehnryr](https://togithub.com/sehnryr) in [https://github.com/bytecodealliance/cargo-component/pull/273](https://togithub.com/bytecodealliance/cargo-component/pull/273)
-   fix kebab case issue by [@&#8203;fibonacci1729](https://togithub.com/fibonacci1729) in [https://github.com/bytecodealliance/cargo-component/pull/274](https://togithub.com/bytecodealliance/cargo-component/pull/274)
-   Help mesasage improvement ([#&#8203;138](https://togithub.com/bytecodealliance/cargo-component/issues/138)) by [@&#8203;chikoski](https://togithub.com/chikoski) in [https://github.com/bytecodealliance/cargo-component/pull/278](https://togithub.com/bytecodealliance/cargo-component/pull/278)
-   Update the example to use the latest version of cargo-component by [@&#8203;rylev](https://togithub.com/rylev) in [https://github.com/bytecodealliance/cargo-component/pull/283](https://togithub.com/bytecodealliance/cargo-component/pull/283)
-   fix test assertions after rust upgrade by [@&#8203;calvinrp](https://togithub.com/calvinrp) in [https://github.com/bytecodealliance/cargo-component/pull/287](https://togithub.com/bytecodealliance/cargo-component/pull/287)
-   Add `profile.release` to `Cargo.toml` generated by `cargo component new` by [@&#8203;calvinrp](https://togithub.com/calvinrp) in [https://github.com/bytecodealliance/cargo-component/pull/289](https://togithub.com/bytecodealliance/cargo-component/pull/289)
-   Update install instruction to use --locked by [@&#8203;fibonacci1729](https://togithub.com/fibonacci1729) in [https://github.com/bytecodealliance/cargo-component/pull/292](https://togithub.com/bytecodealliance/cargo-component/pull/292)
-   Update to latest Warg release to support registry federation by [@&#8203;calvinrp](https://togithub.com/calvinrp) in [https://github.com/bytecodealliance/cargo-component/pull/288](https://togithub.com/bytecodealliance/cargo-component/pull/288)
-   removed unused warg-credentials dependency by [@&#8203;calvinrp](https://togithub.com/calvinrp) in [https://github.com/bytecodealliance/cargo-component/pull/295](https://togithub.com/bytecodealliance/cargo-component/pull/295)
-   Warg update 0.7 by [@&#8203;calvinrp](https://togithub.com/calvinrp) in [https://github.com/bytecodealliance/cargo-component/pull/296](https://togithub.com/bytecodealliance/cargo-component/pull/296)

#### New Contributors

-   [@&#8203;sehnryr](https://togithub.com/sehnryr) made their first contribution in [https://github.com/bytecodealliance/cargo-component/pull/273](https://togithub.com/bytecodealliance/cargo-component/pull/273)
-   [@&#8203;fibonacci1729](https://togithub.com/fibonacci1729) made their first contribution in [https://github.com/bytecodealliance/cargo-component/pull/274](https://togithub.com/bytecodealliance/cargo-component/pull/274)
-   [@&#8203;chikoski](https://togithub.com/chikoski) made their first contribution in [https://github.com/bytecodealliance/cargo-component/pull/278](https://togithub.com/bytecodealliance/cargo-component/pull/278)
-   [@&#8203;calvinrp](https://togithub.com/calvinrp) made their first contribution in [https://github.com/bytecodealliance/cargo-component/pull/287](https://togithub.com/bytecodealliance/cargo-component/pull/287)

**Full Changelog**: bytecodealliance/cargo-component@v0.11.0...v0.12.0

### [`v0.11.0`](https://togithub.com/bytecodealliance/cargo-component/releases/tag/v0.11.0)

[Compare Source](https://togithub.com/bytecodealliance/cargo-component/compare/v0.10.1...v0.11.0)

#### Compatibility

-   Wasmtime: 17.0.0+
-   WASI: 0.2.0
-   Warg (registry support): 0.4.0

#### What's Changed

-   Update wit-bindgen and wasm-tools. by [@&#8203;sunfishcode](https://togithub.com/sunfishcode) in [https://github.com/bytecodealliance/cargo-component/pull/266](https://togithub.com/bytecodealliance/cargo-component/pull/266)
-   Synchronize artifact componentization.  by [@&#8203;peterhuene](https://togithub.com/peterhuene) in [https://github.com/bytecodealliance/cargo-component/pull/270](https://togithub.com/bytecodealliance/cargo-component/pull/270)
-   Bump version to 0.11.0. by [@&#8203;peterhuene](https://togithub.com/peterhuene) in [https://github.com/bytecodealliance/cargo-component/pull/271](https://togithub.com/bytecodealliance/cargo-component/pull/271)

**Full Changelog**: bytecodealliance/cargo-component@v0.10.1...v0.11.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/andrzejressel/pulumi-wasm).
alexcrichton added a commit to alexcrichton/cargo-component that referenced this pull request Jan 14, 2025
This commit effectively reverts bytecodealliance#289 and removes the generated
`[profile.release]` section from `Cargo.toml` when executing `cargo
component new`. The PR mentions that a default release build decreases
from 1.6M to 52KB and that was likely due to stripping DWARF debugging
information rather than many of the other settings configured. Nowadays
for example a default release build (with no extra configuration and no
`profile.release`) is around 50KB because rustc/cargo have started
stripping debuginfo by default in release mode. That means that the
original motivation is still solved, the "default" build is not an
alarmingly large 1.6M.

Otherwise the various settings configured here can have negative effects
which aren't always easy to debug if you're not familiar with them, for
example:

* `lto = true` and `codegen-units = 1` can massively increase the time
  needed for a build. This can be surprising to newcomers who may have
  heard about Rust compile times being bad but this is an order of
  magnitude worse than the default settings. While these two options are
  good rules-of-thumb for a minimally-sized build not everyone falls
  into the category of needing a minimally sized build, and users can
  always configure this themselves.

* `debug = false` is not necessary as it's already the default of the
  `profile.release` in Cargo.

* `strip = true` is no longer necessary in recent versions of
  rustc/Cargo because this is done by default for debuginfo. This is
  otherwise somewhat harmful as it strips the `name` custom section
  which hinders any after-the-fact analysis of a binary because there is
  no symbol information to profile with, for example.

* `opt-level = "s"` is not universally smaller than the default
  `opt-level = "3"` and it can also perform significantly worse. An
  example component I was working with today had a 100% slowdown using
  `opt-level = "s"` relative to `opt-level = "3"`.

Overall I think it's best to inherit Cargo's and Rust's defaults for
these settings by default. There's no one-size-fits-all for all projects
which is why Cargo allows configuring things, but for a template I think
it's best to inherit default settings since that'll ideally cause the
least surprise for users who aren't otherwise familiar with these settings.
alexcrichton added a commit that referenced this pull request Jan 21, 2025
This commit effectively reverts #289 and removes the generated
`[profile.release]` section from `Cargo.toml` when executing `cargo
component new`. The PR mentions that a default release build decreases
from 1.6M to 52KB and that was likely due to stripping DWARF debugging
information rather than many of the other settings configured. Nowadays
for example a default release build (with no extra configuration and no
`profile.release`) is around 50KB because rustc/cargo have started
stripping debuginfo by default in release mode. That means that the
original motivation is still solved, the "default" build is not an
alarmingly large 1.6M.

Otherwise the various settings configured here can have negative effects
which aren't always easy to debug if you're not familiar with them, for
example:

* `lto = true` and `codegen-units = 1` can massively increase the time
  needed for a build. This can be surprising to newcomers who may have
  heard about Rust compile times being bad but this is an order of
  magnitude worse than the default settings. While these two options are
  good rules-of-thumb for a minimally-sized build not everyone falls
  into the category of needing a minimally sized build, and users can
  always configure this themselves.

* `debug = false` is not necessary as it's already the default of the
  `profile.release` in Cargo.

* `strip = true` is no longer necessary in recent versions of
  rustc/Cargo because this is done by default for debuginfo. This is
  otherwise somewhat harmful as it strips the `name` custom section
  which hinders any after-the-fact analysis of a binary because there is
  no symbol information to profile with, for example.

* `opt-level = "s"` is not universally smaller than the default
  `opt-level = "3"` and it can also perform significantly worse. An
  example component I was working with today had a 100% slowdown using
  `opt-level = "s"` relative to `opt-level = "3"`.

Overall I think it's best to inherit Cargo's and Rust's defaults for
these settings by default. There's no one-size-fits-all for all projects
which is why Cargo allows configuring things, but for a template I think
it's best to inherit default settings since that'll ideally cause the
least surprise for users who aren't otherwise familiar with these settings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants