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
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ rustflags = ["--cfg", "tokio_unstable"]
bump-versions = "run -p upgrade-version --"
llm = "run --package xtask-llm-benchmark --bin llm_benchmark --"
ci = "run -p ci --"
regen = "run -p regen --"
smoketest = "ci smoketests --"
smoketests = "smoketest"
lint = "ci lint --"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ jobs:
}

- name: Hydrate Unity SDK DLLs
run: cargo ci dlls
run: cargo regen csharp dlls

- name: Check Unity meta files
uses: DeNA/unity-meta-check@v3
Expand Down
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ members = [
"tools/replace-spacetimedb",
"tools/generate-client-api",
"tools/gen-bindings",
"tools/regen",
"tools/xtask-llm-benchmark",
"crates/bindings-typescript/test-app/server",
"crates/bindings-typescript/test-react-router-app/server",
Expand Down
4 changes: 2 additions & 2 deletions tools/ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ Usage: wasm-bindings

### `dlls`

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

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.
Builds and packs C# DLLs and NuGet packages for local Unity workflows.

**Usage:**
```bash
Expand Down
204 changes: 4 additions & 200 deletions tools/ci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,123 +91,6 @@ fn check_global_json_policy() -> Result<()> {
Ok(())
}

fn overlay_unity_meta_skeleton(pkg_id: &str) -> Result<()> {
let skeleton_base = Path::new("sdks/csharp/unity-meta-skeleton~");
let skeleton_root = skeleton_base.join(pkg_id);
if !skeleton_root.exists() {
return Ok(());
}

let pkg_root = Path::new("sdks/csharp/packages").join(pkg_id);
if !pkg_root.exists() {
return Ok(());
}

// Copy spacetimedb.<pkg>.meta
let pkg_root_meta = skeleton_base.join(format!("{pkg_id}.meta"));
if pkg_root_meta.exists()
&& let Some(parent) = pkg_root.parent()
{
let pkg_meta_dst = parent.join(format!("{pkg_id}.meta"));
fs::copy(&pkg_root_meta, &pkg_meta_dst)?;
}

let versioned_dir = match find_only_subdir(&pkg_root) {
Ok(dir) => dir,
Err(err) => {
log::info!("Skipping Unity meta overlay for {pkg_id}: could not locate restored version dir: {err}");
return Ok(());
}
};

// If version.meta exists under the skeleton package, rename it to match the restored version dir.
let version_meta_template = skeleton_root.join("version.meta");
if version_meta_template.exists()
&& let Some(parent) = versioned_dir.parent()
{
let version_name = versioned_dir
.file_name()
.expect("versioned directory should have a file name");
let version_meta_dst = parent.join(format!("{}.meta", version_name.to_string_lossy()));
fs::copy(&version_meta_template, &version_meta_dst)?;
}

copy_overlay_dir(&skeleton_root, &versioned_dir)
}

fn clear_restored_package_dirs(pkg_id: &str) -> Result<()> {
let pkg_root = Path::new("sdks/csharp/packages").join(pkg_id);
if !pkg_root.exists() {
return Ok(());
}

fs::remove_dir_all(&pkg_root)?;

Ok(())
}

fn find_only_subdir(dir: &Path) -> Result<PathBuf> {
let mut subdirs: Vec<PathBuf> = vec![];

for entry in fs::read_dir(dir)? {
let entry = entry?;
if entry.file_type()?.is_dir() {
subdirs.push(entry.path());
}
}

match subdirs.as_slice() {
[] => Err(anyhow::anyhow!(
"Could not find a restored versioned directory under {}",
dir.display()
)),
[only] => Ok(only.clone()),
_ => Err(anyhow::anyhow!(
"Expected exactly one restored versioned directory under {}, found {}",
dir.display(),
subdirs.len()
)),
}
}

fn copy_overlay_dir(src: &Path, dst: &Path) -> Result<()> {
if !src.exists() {
bail!("Skeleton directory does not exist: {}", src.display());
}
if !dst.exists() {
bail!("Destination directory does not exist: {}", dst.display());
}

for entry in fs::read_dir(src)? {
let entry = entry?;
let src_path = entry.path();
let dst_path = dst.join(entry.file_name());
if entry.file_type()?.is_dir() {
if dst_path.exists() {
copy_overlay_dir(&src_path, &dst_path)?;
}
} else {
if src_path.extension() == Some(OsStr::new("meta")) {
let asset_path = dst_path
.parent()
.expect("dst_path should have a parent")
.join(dst_path.file_stem().expect(".meta file should have a file stem"));

if asset_path.exists() {
fs::copy(&src_path, &dst_path)?;
} else if dst_path.exists() {
fs::remove_file(&dst_path)?;
}
continue;
}

fs::copy(&src_path, &dst_path)?;
}
}

Ok(())
}

#[derive(Subcommand)]
enum CiCmd {
/// Runs tests
Expand All @@ -225,11 +108,9 @@ enum CiCmd {
///
/// Runs tests for the codegen crate and builds a test module with the wasm bindings.
WasmBindings,
/// Builds and packs C# DLLs and NuGet packages for local Unity workflows
/// Deprecated; use `cargo regen csharp dlls`.
///
/// 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.
/// Builds and packs C# DLLs and NuGet packages for local Unity workflows.
Dlls,
/// Runs smoketests
///
Expand Down Expand Up @@ -308,84 +189,6 @@ fn tracked_rs_files_under(path: &str) -> Result<Vec<PathBuf>> {
.collect())
}

fn run_dlls() -> Result<()> {
ensure_repo_root()?;

cmd!(
"dotnet",
"pack",
"crates/bindings-csharp/BSATN.Runtime",
"-c",
"Release"
)
.run()?;
cmd!("dotnet", "pack", "crates/bindings-csharp/Runtime", "-c", "Release").run()?;

let repo_root = env::current_dir()?;
let bsatn_source = repo_root.join("crates/bindings-csharp/BSATN.Runtime/bin/Release");
let runtime_source = repo_root.join("crates/bindings-csharp/Runtime/bin/Release");

let nuget_config_dir = tempfile::tempdir()?;
let nuget_config_path = nuget_config_dir.path().join("nuget.config");
let nuget_config_contents = format!(
r#"<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="Local SpacetimeDB.BSATN.Runtime" value="{}" />
<add key="Local SpacetimeDB.Runtime" value="{}" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="Local SpacetimeDB.BSATN.Runtime">
<package pattern="SpacetimeDB.BSATN.Runtime" />
</packageSource>
<packageSource key="Local SpacetimeDB.Runtime">
<package pattern="SpacetimeDB.Runtime" />
</packageSource>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
"#,
bsatn_source.display(),
runtime_source.display(),
);
fs::write(&nuget_config_path, nuget_config_contents)?;

let nuget_config_path_str = nuget_config_path.to_string_lossy().to_string();

clear_restored_package_dirs("spacetimedb.bsatn.runtime")?;
clear_restored_package_dirs("spacetimedb.runtime")?;

cmd!(
"dotnet",
"restore",
"SpacetimeDB.ClientSDK.csproj",
"--configfile",
&nuget_config_path_str,
)
.dir("sdks/csharp")
.run()?;

overlay_unity_meta_skeleton("spacetimedb.bsatn.runtime")?;
overlay_unity_meta_skeleton("spacetimedb.runtime")?;

cmd!(
"dotnet",
"pack",
"SpacetimeDB.ClientSDK.csproj",
"-c",
"Release",
"--no-restore"
)
.dir("sdks/csharp")
.run()?;

Ok(())
}

fn run_publish_checks() -> Result<()> {
cmd!("bash", "-lc", "test -d venv || python3 -m venv venv").run()?;
cmd!("venv/bin/pip3", "install", "argparse", "toml").run()?;
Expand Down Expand Up @@ -623,7 +426,8 @@ fn main() -> Result<()> {
}

Some(CiCmd::Dlls) => {
run_dlls()?;
eprintln!("warning: `cargo ci dlls` is deprecated; use `cargo regen csharp dlls` instead");
cmd!("cargo", "regen", "csharp", "dlls").run()?;
}

Some(CiCmd::Smoketests(args)) => {
Expand Down
10 changes: 10 additions & 0 deletions tools/regen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "regen"
version = "0.1.0"
edition.workspace = true

[dependencies]
anyhow.workspace = true
clap.workspace = true
duct.workspace = true
tempfile.workspace = true
Loading
Loading