Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ regen = "run -p regen --"
smoketest = "ci smoketests --"
smoketests = "smoketest"
lint = "ci lint --"

fmt = "ci fmt --"
[target.x86_64-pc-windows-msvc]
# Use a different linker. Otherwise, the build fails with some obscure linker error that
# seems to be a result of us producing a massive PDB file.
Expand All @@ -19,3 +19,6 @@ linker = "lld-link"
# Without this, the linker complains that libc functions are undefined -
# it probably signals to rustc and lld-link that libucrt should be included.
rustflags = ["-Ctarget-feature=+crt-static"]

[net]
git-fetch-with-cli = true
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ members = [
"tools/ci",
"tools/ci/commands/test",
"tools/ci/commands/lint",
"tools/ci/commands/lint",
"tools/ci/commands/fmt",
"tools/ci/commands/module-latest-deps",
"tools/ci/commands/smoketests",
"tools/ci/commands/smoketest-checks",
Expand Down
8 changes: 5 additions & 3 deletions docs/src/client-modules/inkeep-font-override.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

function injectInkeepFontOverride() {
// Find all Inkeep shadow DOM containers
const inkeepElements = document.querySelectorAll('[id^="inkeep-shadowradix"]');
const inkeepElements = document.querySelectorAll(
'[id^="inkeep-shadowradix"]'
);

inkeepElements.forEach((element) => {
inkeepElements.forEach(element => {
const shadowRoot = element.shadowRoot;
if (!shadowRoot) return;

Expand Down Expand Up @@ -75,7 +77,7 @@ if (typeof window !== 'undefined') {
}

// Also observe for dynamically added Inkeep elements
const observer = new MutationObserver((mutations) => {
const observer = new MutationObserver(mutations => {
for (const mutation of mutations) {
if (mutation.type === 'childList') {
injectInkeepFontOverride();
Expand Down
12 changes: 12 additions & 0 deletions tools/ci/commands/fmt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

[package]
name = "ci-fmt"
version = "0.1.0"
edition.workspace = true

[dependencies]
anyhow.workspace = true
clap.workspace = true
duct.workspace = true
ci-common = { path = "../../common" }

67 changes: 67 additions & 0 deletions tools/ci/commands/fmt/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#![allow(clippy::disallowed_macros)]
use anyhow::{Context, Result};
use ci_common::{ensure_repo_root, pnpm};
use clap::Parser;
use duct::cmd;
use std::ffi::OsString;
use std::path::PathBuf;

/// Formats the codebase
///
/// Runs rustfmt, csharpier, and the TypeScript/JS formatter (`pnpm format`) in
/// write mode, so a single `cargo fmt` fixes formatting everywhere in the repo.
/// This mirrors `cargo ci lint`'s checks, but writes fixes instead of only
/// checking for them.
#[derive(Parser)]
struct Cli {}

// NOTE: duplicated from `ci-lint`'s `tracked_rs_files_under`. `cargo fmt --all`
// only checks files that Cargo discovers through workspace/package targets,
// but we also keep Rust sources in locations that are tracked but not part of
// our workspace, so we enumerate tracked files directly instead, exactly like
// `ci-lint` does for its `--check` pass. If this feels worth deduplicating,
// it could move to `ci-common`.
fn tracked_rs_files_under(path: &str) -> Result<Vec<PathBuf>> {
let output = cmd!("git", "ls-files", "--", path)
.read()
.with_context(|| format!("failed to list tracked files under {path}"))?;
Ok(output
.lines()
.filter(|line| line.ends_with(".rs"))
.map(PathBuf::from)
.collect())
}

fn main() -> Result<()> {
Cli::parse();
ensure_repo_root()?;

// Format Rust files.
let files = tracked_rs_files_under(".")?;
const RUSTFMT_BATCH_SIZE: usize = 200;
for batch in files.chunks(RUSTFMT_BATCH_SIZE) {
let mut args = Vec::<OsString>::with_capacity(batch.len());
args.extend(batch.iter().map(|path| path.as_os_str().to_os_string()));
cmd("rustfmt", args)
.run()
.context("failed to run rustfmt")?;
}

// Format C# files.
cmd!("dotnet", "tool", "restore")
.dir("crates/bindings-csharp")
.run()
.context("failed to run `dotnet tool restore` in crates/bindings-csharp")?;
cmd!("dotnet", "csharpier", ".")
.dir("crates/bindings-csharp")
.run()
.context("failed to run `dotnet csharpier .` in crates/bindings-csharp")?;

// Format TypeScript/JS files. This script already exists in package.json
// and is what `pnpm format` runs today.
pnpm(["format"])
.run()
.context("failed to run `pnpm format`")?;

Ok(())
}
4 changes: 4 additions & 0 deletions tools/ci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ const COMMANDS: &[Command] = &[
path: &["other-workflows", "run-spacetime"],
package: "ci-run-spacetime",
},
Command {
path: &["fmt"],
package: "ci-fmt",
},
];

fn print_help() {
Expand Down