Skip to content

Commit 8df7df3

Browse files
authored
cargo ci dlls -> cargo regen csharp dlls (clockworklabs#4972)
# Description of Changes Just moving this command in preparation to create a lot more `cargo regen` commands. - `master` - **[This PR] `cargo ci dlls` -> `cargo regen csharp dlls`** - [clockworklabs#4971 Translate some bash scripts to Rust](clockworklabs#4971) - [clockworklabs#4921 CI - `cargo test` runs C# and TypeScript tests](clockworklabs#4921) - [clockworklabs#4948 CI - Run unity tests through `cargo test`](clockworklabs#4948) # API and ABI breaking changes None # Expected complexity level and risk 1 # Testing - [x] CI still passes --------- Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
1 parent af50bf5 commit 8df7df3

9 files changed

Lines changed: 304 additions & 203 deletions

File tree

.cargo/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ rustflags = ["--cfg", "tokio_unstable"]
55
bump-versions = "run -p upgrade-version --"
66
llm = "run --package xtask-llm-benchmark --bin llm_benchmark --"
77
ci = "run -p ci --"
8+
regen = "run -p regen --"
89
smoketest = "ci smoketests --"
910
smoketests = "smoketest"
1011
lint = "ci lint --"

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ jobs:
689689
}
690690
691691
- name: Hydrate Unity SDK DLLs
692-
run: cargo ci dlls
692+
run: cargo regen csharp dlls
693693

694694
- name: Check Unity meta files
695695
uses: DeNA/unity-meta-check@v3

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ members = [
6565
"tools/replace-spacetimedb",
6666
"tools/generate-client-api",
6767
"tools/gen-bindings",
68+
"tools/regen",
6869
"tools/xtask-llm-benchmark",
6970
"crates/bindings-typescript/test-app/server",
7071
"crates/bindings-typescript/test-react-router-app/server",

tools/ci/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ Usage: wasm-bindings
7272

7373
### `dlls`
7474

75-
Builds and packs C# DLLs and NuGet packages for local Unity workflows
75+
Deprecated; use `cargo regen csharp dlls`.
7676

77-
Packs the in-repo C# NuGet packages and restores the C# SDK to populate `sdks/csharp/packages/**`. Then overlays Unity `.meta` skeleton files from `sdks/csharp/unity-meta-skeleton~/**` onto the restored versioned package directory, so Unity can associate stable meta files with the most recently built package.
77+
Builds and packs C# DLLs and NuGet packages for local Unity workflows.
7878

7979
**Usage:**
8080
```bash

tools/ci/src/main.rs

Lines changed: 4 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -91,123 +91,6 @@ fn check_global_json_policy() -> Result<()> {
9191
Ok(())
9292
}
9393

94-
fn overlay_unity_meta_skeleton(pkg_id: &str) -> Result<()> {
95-
let skeleton_base = Path::new("sdks/csharp/unity-meta-skeleton~");
96-
let skeleton_root = skeleton_base.join(pkg_id);
97-
if !skeleton_root.exists() {
98-
return Ok(());
99-
}
100-
101-
let pkg_root = Path::new("sdks/csharp/packages").join(pkg_id);
102-
if !pkg_root.exists() {
103-
return Ok(());
104-
}
105-
106-
// Copy spacetimedb.<pkg>.meta
107-
let pkg_root_meta = skeleton_base.join(format!("{pkg_id}.meta"));
108-
if pkg_root_meta.exists()
109-
&& let Some(parent) = pkg_root.parent()
110-
{
111-
let pkg_meta_dst = parent.join(format!("{pkg_id}.meta"));
112-
fs::copy(&pkg_root_meta, &pkg_meta_dst)?;
113-
}
114-
115-
let versioned_dir = match find_only_subdir(&pkg_root) {
116-
Ok(dir) => dir,
117-
Err(err) => {
118-
log::info!("Skipping Unity meta overlay for {pkg_id}: could not locate restored version dir: {err}");
119-
return Ok(());
120-
}
121-
};
122-
123-
// If version.meta exists under the skeleton package, rename it to match the restored version dir.
124-
let version_meta_template = skeleton_root.join("version.meta");
125-
if version_meta_template.exists()
126-
&& let Some(parent) = versioned_dir.parent()
127-
{
128-
let version_name = versioned_dir
129-
.file_name()
130-
.expect("versioned directory should have a file name");
131-
let version_meta_dst = parent.join(format!("{}.meta", version_name.to_string_lossy()));
132-
fs::copy(&version_meta_template, &version_meta_dst)?;
133-
}
134-
135-
copy_overlay_dir(&skeleton_root, &versioned_dir)
136-
}
137-
138-
fn clear_restored_package_dirs(pkg_id: &str) -> Result<()> {
139-
let pkg_root = Path::new("sdks/csharp/packages").join(pkg_id);
140-
if !pkg_root.exists() {
141-
return Ok(());
142-
}
143-
144-
fs::remove_dir_all(&pkg_root)?;
145-
146-
Ok(())
147-
}
148-
149-
fn find_only_subdir(dir: &Path) -> Result<PathBuf> {
150-
let mut subdirs: Vec<PathBuf> = vec![];
151-
152-
for entry in fs::read_dir(dir)? {
153-
let entry = entry?;
154-
if entry.file_type()?.is_dir() {
155-
subdirs.push(entry.path());
156-
}
157-
}
158-
159-
match subdirs.as_slice() {
160-
[] => Err(anyhow::anyhow!(
161-
"Could not find a restored versioned directory under {}",
162-
dir.display()
163-
)),
164-
[only] => Ok(only.clone()),
165-
_ => Err(anyhow::anyhow!(
166-
"Expected exactly one restored versioned directory under {}, found {}",
167-
dir.display(),
168-
subdirs.len()
169-
)),
170-
}
171-
}
172-
173-
fn copy_overlay_dir(src: &Path, dst: &Path) -> Result<()> {
174-
if !src.exists() {
175-
bail!("Skeleton directory does not exist: {}", src.display());
176-
}
177-
if !dst.exists() {
178-
bail!("Destination directory does not exist: {}", dst.display());
179-
}
180-
181-
for entry in fs::read_dir(src)? {
182-
let entry = entry?;
183-
let src_path = entry.path();
184-
let dst_path = dst.join(entry.file_name());
185-
if entry.file_type()?.is_dir() {
186-
if dst_path.exists() {
187-
copy_overlay_dir(&src_path, &dst_path)?;
188-
}
189-
} else {
190-
if src_path.extension() == Some(OsStr::new("meta")) {
191-
let asset_path = dst_path
192-
.parent()
193-
.expect("dst_path should have a parent")
194-
.join(dst_path.file_stem().expect(".meta file should have a file stem"));
195-
196-
if asset_path.exists() {
197-
fs::copy(&src_path, &dst_path)?;
198-
} else if dst_path.exists() {
199-
fs::remove_file(&dst_path)?;
200-
}
201-
continue;
202-
}
203-
204-
fs::copy(&src_path, &dst_path)?;
205-
}
206-
}
207-
208-
Ok(())
209-
}
210-
21194
#[derive(Subcommand)]
21295
enum CiCmd {
21396
/// Runs tests
@@ -225,11 +108,9 @@ enum CiCmd {
225108
///
226109
/// Runs tests for the codegen crate and builds a test module with the wasm bindings.
227110
WasmBindings,
228-
/// Builds and packs C# DLLs and NuGet packages for local Unity workflows
111+
/// Deprecated; use `cargo regen csharp dlls`.
229112
///
230-
/// Packs the in-repo C# NuGet packages and restores the C# SDK to populate `sdks/csharp/packages/**`.
231-
/// Then overlays Unity `.meta` skeleton files from `sdks/csharp/unity-meta-skeleton~/**` onto the restored
232-
/// versioned package directory, so Unity can associate stable meta files with the most recently built package.
113+
/// Builds and packs C# DLLs and NuGet packages for local Unity workflows.
233114
Dlls,
234115
/// Runs smoketests
235116
///
@@ -308,84 +189,6 @@ fn tracked_rs_files_under(path: &str) -> Result<Vec<PathBuf>> {
308189
.collect())
309190
}
310191

311-
fn run_dlls() -> Result<()> {
312-
ensure_repo_root()?;
313-
314-
cmd!(
315-
"dotnet",
316-
"pack",
317-
"crates/bindings-csharp/BSATN.Runtime",
318-
"-c",
319-
"Release"
320-
)
321-
.run()?;
322-
cmd!("dotnet", "pack", "crates/bindings-csharp/Runtime", "-c", "Release").run()?;
323-
324-
let repo_root = env::current_dir()?;
325-
let bsatn_source = repo_root.join("crates/bindings-csharp/BSATN.Runtime/bin/Release");
326-
let runtime_source = repo_root.join("crates/bindings-csharp/Runtime/bin/Release");
327-
328-
let nuget_config_dir = tempfile::tempdir()?;
329-
let nuget_config_path = nuget_config_dir.path().join("nuget.config");
330-
let nuget_config_contents = format!(
331-
r#"<?xml version="1.0" encoding="utf-8"?>
332-
<configuration>
333-
<packageSources>
334-
<clear />
335-
<add key="Local SpacetimeDB.BSATN.Runtime" value="{}" />
336-
<add key="Local SpacetimeDB.Runtime" value="{}" />
337-
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
338-
</packageSources>
339-
<packageSourceMapping>
340-
<packageSource key="Local SpacetimeDB.BSATN.Runtime">
341-
<package pattern="SpacetimeDB.BSATN.Runtime" />
342-
</packageSource>
343-
<packageSource key="Local SpacetimeDB.Runtime">
344-
<package pattern="SpacetimeDB.Runtime" />
345-
</packageSource>
346-
<packageSource key="nuget.org">
347-
<package pattern="*" />
348-
</packageSource>
349-
</packageSourceMapping>
350-
</configuration>
351-
"#,
352-
bsatn_source.display(),
353-
runtime_source.display(),
354-
);
355-
fs::write(&nuget_config_path, nuget_config_contents)?;
356-
357-
let nuget_config_path_str = nuget_config_path.to_string_lossy().to_string();
358-
359-
clear_restored_package_dirs("spacetimedb.bsatn.runtime")?;
360-
clear_restored_package_dirs("spacetimedb.runtime")?;
361-
362-
cmd!(
363-
"dotnet",
364-
"restore",
365-
"SpacetimeDB.ClientSDK.csproj",
366-
"--configfile",
367-
&nuget_config_path_str,
368-
)
369-
.dir("sdks/csharp")
370-
.run()?;
371-
372-
overlay_unity_meta_skeleton("spacetimedb.bsatn.runtime")?;
373-
overlay_unity_meta_skeleton("spacetimedb.runtime")?;
374-
375-
cmd!(
376-
"dotnet",
377-
"pack",
378-
"SpacetimeDB.ClientSDK.csproj",
379-
"-c",
380-
"Release",
381-
"--no-restore"
382-
)
383-
.dir("sdks/csharp")
384-
.run()?;
385-
386-
Ok(())
387-
}
388-
389192
fn run_publish_checks() -> Result<()> {
390193
cmd!("bash", "-lc", "test -d venv || python3 -m venv venv").run()?;
391194
cmd!("venv/bin/pip3", "install", "argparse", "toml").run()?;
@@ -623,7 +426,8 @@ fn main() -> Result<()> {
623426
}
624427

625428
Some(CiCmd::Dlls) => {
626-
run_dlls()?;
429+
eprintln!("warning: `cargo ci dlls` is deprecated; use `cargo regen csharp dlls` instead");
430+
cmd!("cargo", "regen", "csharp", "dlls").run()?;
627431
}
628432

629433
Some(CiCmd::Smoketests(args)) => {

tools/regen/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "regen"
3+
version = "0.1.0"
4+
edition.workspace = true
5+
6+
[dependencies]
7+
anyhow.workspace = true
8+
clap.workspace = true
9+
duct.workspace = true
10+
tempfile.workspace = true

0 commit comments

Comments
 (0)