Skip to content

Commit

Permalink
chore: move all workspace dependencies to workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Nov 21, 2024
1 parent c5ef6c4 commit a5d634d
Show file tree
Hide file tree
Showing 12 changed files with 1,024 additions and 413 deletions.
32 changes: 32 additions & 0 deletions Cargo.lock

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

1,152 changes: 852 additions & 300 deletions Cargo.toml

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions packages/infra/client/Cargo.lock

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

13 changes: 13 additions & 0 deletions packages/infra/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,16 @@ members = [
"manager",
"runner-protocol",
]

[workspace.package]
version = "0.0.1"
edition = "2021"
authors = ["Rivet Gaming, LLC <[email protected]>"]
license = "Apache-2.0"

[workspace.dependencies]
container-runner = { path = "container-runner" }
echo = { path = "echo" }
isolate-v8-runner = { path = "isolate-v8-runner" }
runner-protocol = { path = "runner-protocol", package = "pegboard-runner-protocol" }

27 changes: 0 additions & 27 deletions packages/services/cluster/src/ops/server/dc-init/Cargo.toml

This file was deleted.

54 changes: 0 additions & 54 deletions packages/services/cluster/src/ops/server/dc-init/src/lib.rs

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion packages/services/ds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ tier = { path = "../tier" }
token-create = { path = "../token/ops/create" }
upload-get = { path = "../upload/ops/get" }
user-identity-get = { path = "../user-identity/ops/get" }
rivet-config = { path = "../../common/config" }
rivet-config.workspace = true

[dependencies.sqlx]
path = "../../../externals/sqlx"
Expand Down
92 changes: 92 additions & 0 deletions scripts/cargo/update_workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env -S deno run --allow-net --allow-env --allow-read --allow-write

import { parse, stringify } from "@std/toml";
import { walk } from "@std/fs";
import { join, relative } from "@std/path";

const rootDir = join(import.meta.dirname, "../..");

async function updateCargoToml() {
const workspaceTomlPath = join(rootDir, "Cargo.toml");
const workspaceTomlContent = await Deno.readTextFile(workspaceTomlPath);
const workspaceToml = parse(workspaceTomlContent);

// Find all workspace members
const members: string[] = [];
for await (
const entry of walk(join(rootDir, "packages"), {
includeDirs: false,
exts: ["toml"],
})
) {
// Exclude infra packages
if (
entry.path.includes("packages/infra/client") ||
entry.path.includes("packages/infra/job-runner")
) {
continue;
}

const packagePath = relative(
rootDir,
entry.path.replace(/\/Cargo\.toml$/, ""),
);
members.push(packagePath);
}

// Hardcode extra workspace members
members.push("sdks/full/rust");

// Remove path dependencies, since we'll replace these. This lets us
// preserve existing external dependencies.
const existingDependencies = workspaceToml.workspace?.dependencies || {};
for (const [name, dep] of Object.entries(existingDependencies)) {
if (dep && typeof dep === "object" && "path" in dep) {
delete existingDependencies[name];
}
}

// Build new workspace dependencies
const newDependencies: Record<string, any> = {};
for (const packagePath of members) {
const packageTomlPath = join(rootDir, packagePath, "Cargo.toml");
const packageTomlContent = await Deno.readTextFile(packageTomlPath);
const packageToml = parse(packageTomlContent);

// Save to workspace
newDependencies[packageToml.package.name] = {
path: packagePath,
};

// // Replace all package dependencies that refer to a workspace package to use `*.workspace = true`
// for (
// const [depName, dep] of Object.entries(packageToml.dependencies || {})
// ) {
// if (dep && typeof dep === "object" && "path" in dep) {
// const depAbsolutePath = join(packagePath, dep.path);
// const depRelativePath = relative(rootDir, depAbsolutePath);
// if (members.includes(depRelativePath)) {
// delete packageToml.dependencies[depName].path;
// packageToml.dependencies[depName].workspace = true;
// }
// }
// }

// // Write the updated package Cargo.toml
// const updatedPackageTomlContent = stringify(packageToml);
// await Deno.writeTextFile(packageTomlPath, updatedPackageTomlContent);
}

// Update and write workspace
workspaceToml.workspace = workspaceToml.workspace || {};
workspaceToml.workspace.members = members;
workspaceToml.workspace.dependencies = {
...existingDependencies,
...newDependencies,
};

const updatedTomlContent = stringify(workspaceToml);
await Deno.writeTextFile(workspaceTomlPath, updatedTomlContent);
}

updateCargoToml().catch(console.error);
Loading

0 comments on commit a5d634d

Please sign in to comment.