This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Add Cargo tips #42
Open
ELD
wants to merge
3
commits into
main
Choose a base branch
from
cargo-tips
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Cargo tips #42
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
name: .cargo/config.toml | ||
description: Cargo is the package manager and build tool for the Rust programming language. It's used to manage metadata, targets, dependencies, and more. | ||
website: https://doc.rust-lang.org/stable/cargo/ | ||
logo: simple-icons:rust | ||
body: | | ||
The Cargo configuration file (`config.toml`) can be found in a variety of places: | ||
- `my-project/.cargo/config.toml` | ||
- `/.cargo/config.toml` | ||
- `$CARGO_HOME/config.toml` | ||
|
||
Using this file, you can configure all kinds of settings as they relate to building, aliasing commands, setting environment variables, configuring registry resolution, and more! | ||
snippet: | ||
lang: toml | ||
filePath: "Cargo.toml" | ||
code: | | ||
[alias] | ||
b = "build" | ||
t = "test" | ||
|
||
[build] | ||
jobs = 16 | ||
rustc-wrapper = "/path/to/sccache" | ||
target-dir = "target" | ||
|
||
[cargo-new] | ||
vcs = "hg" | ||
|
||
[target.aarch64-apple-darwin] | ||
rustflags = ["-C", "link-arg=-fuse-ld=/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
name: Cargo.toml | ||
description: Cargo is the package manager and build tool for the Rust programming language. It's used to manage metadata, targets, dependencies, and more. | ||
website: https://doc.rust-lang.org/stable/cargo/ | ||
logo: simple-icons:rust | ||
body: > | ||
`Cargo.toml` is a manifest file for Rust projects, which includes things like metadata (project name, author, license, etc.), a list of targets (i.e. binaries, libraries, etc.), and dependencies for the project. | ||
In a standard Rust project, a Cargo.toml is in the root of the project and a sibling to the `src/` directory. Using Cargo, it generates a `Cargo.lock` file that can ensure predictable and reproducible dependency resolution between copies of the project. | ||
snippet: | ||
lang: toml | ||
filePath: "Cargo.toml" | ||
code: | | ||
[package] | ||
name = "my-rust-project" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "my-binary" | ||
path = "src/bin/main.rs" | ||
|
||
[lib] | ||
name = "libmy_binary" | ||
path = "src/lib.rs" | ||
|
||
[dependencies] | ||
clap = { version = "4.4.0", features = ["derive"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
kind: cargo-config-toml | ||
title: Changing Rust linker for faster compile times | ||
description: | | ||
Changing the linker for your Rust project can significantly speed up | ||
compile times. Here's how to do it! | ||
contributor: https://github.com/ELD | ||
snippet: | | ||
[target.aarch64-apple-darwin] | ||
rustflags = ["-C", "link-arg=-fuse-ld=/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"] | ||
|
||
[target.target.x86_64-unknown-linux-gnu] | ||
rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] | ||
--- | ||
|
||
In the example snippet, we're setting the linker to use | ||
[`mold`](https://github.com/rui314/mold) for Linux | ||
targets and the new `ld-prime` linker on macOS (leveraging the Xcode 15 beta | ||
command line tools). | ||
|
||
Both linkers take advantage of multiple cores on your machine and significantly | ||
speed up compile times. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
kind: cargo-toml | ||
title: Patching a dependency in your project | ||
description: | | ||
Sometimes you want to patch a dependency in your project to incorporate a | ||
patch or feature preview. This tip will show you how! | ||
contributor: https://github.com/ELD | ||
snippet: | | ||
[dependencies] | ||
cool_webframework = "0.1" | ||
|
||
[patch.crates-io] | ||
cool_webframework = { git = "https://github.com/foo/cool_webframework.git", branch = "preview_release" } | ||
--- | ||
|
||
Sometimes, a crate you're using requires a fix or the feature or change you're | ||
waiting for is in a pull request (and subsequently someone's fork of the repo). | ||
To use that change, use the `[patch]` section of your `Cargo.toml`! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
kind: cargo-config-toml | ||
title: Add sccache to speed up your Rust build times | ||
description: | | ||
Use the `sccache` utility to cache compiled artifacts to speed up | ||
successive Rust compile-times in addition to the speed of debug/incremental | ||
builds. | ||
contributor: https://github.com/ELD | ||
snippet: | | ||
[build] | ||
rustc-wrapper = "/path/to/sccache" | ||
--- | ||
|
||
Using the `sscache` compiler caching utility, you can speed up your successive | ||
compilations by adding the following snippet to your Cargo configuration. This | ||
wraps the `rustc` binary and allows it to search for precompiled artifacts | ||
before resorting to compiling again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,23 @@ import type { BreadCrumbList } from '../../../components/Navigation/BreadCrumb.a | |
|
||
export async function getStaticPaths() { | ||
const configKinds = await getCollection("configKinds"); | ||
const renderer = new marked.Renderer(); | ||
|
||
// Custom render lists in the body | ||
renderer.list = (body, ordered) => { | ||
const type = ordered ? 'ol' : 'ul'; | ||
const className = ordered ? 'list-decimal' : 'list-disc'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll fix this up in #48 since it deals with that change (this PR is rebased on top of that branch) |
||
|
||
return ` | ||
<div class="text-left"> | ||
<${type} class="${className} list-inside text-left">${body}</${type}> | ||
</div>`; | ||
}; | ||
|
||
const paths = await Promise.all(configKinds.map(async (configKind) => { | ||
const allTips = await getCollection("tips"); | ||
const tips = allTips.filter(tip => tip.data.kind.id === configKind.id); | ||
const htmlBody = marked(configKind.data.body); | ||
const htmlBody = marked(configKind.data.body, { renderer }); | ||
return { | ||
params: { configKind: configKind.id }, | ||
props: { configKind, tips, htmlBody }, | ||
|
@@ -67,4 +79,4 @@ const breadCrumbList: BreadCrumbList = [ | |
))} | ||
</div> | ||
</div> | ||
</Layout> | ||
</Layout> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the name, Let's call this Cargo? Or Cargo Config? Would something like that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh i missed how there are two very similar kinds. But I notice they both have the same filepath in their kinds? Should these maybe be one type? I don't know much about rust/cargo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue I found here is that project configuration is in a
Cargo.toml
file in the root of the project.The actual configuration for the Cargo utility is in a
.cargo/config.toml
file and the two are exclusive, i.e. you can't mix configuration options in aCargo.toml
that belong in a.cargo/config.toml
. So, I built two separate collections since it seemed like we were keying off the file name or configuration type.Happy to rethink the way we're presenting Rust, though!