MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / build_csharp

Function build_csharp

crates/cli/src/tasks/csharp.rs:11–109  ·  view source on GitHub ↗
(project_path: &Path, build_debug: bool)

Source from the content-addressed store, hash-verified

9}
10
11pub(crate) fn build_csharp(project_path: &Path, build_debug: bool) -> anyhow::Result<PathBuf> {
12 // All `dotnet` commands must execute in the project directory, otherwise
13 // global.json won't have any effect and wrong .NET SDK might be picked.
14 macro_rules! dotnet {
15 ($($arg:expr),*) => {
16 duct::cmd!("dotnet", $($arg),*).dir(project_path)
17 };
18 }
19
20 // Check if the `wasi-experimental` workload is installed. Unfortunately, we
21 // have to do this by inspecting the human-readable output. There is a
22 // hidden `--machine-readable` flag but it also mixes in human-readable
23 // output as well as unnecessarily updates various unrelated manifests.
24 match dotnet!("workload", "list").read() {
25 Ok(workloads) if workloads.contains("wasi-experimental") => {}
26 Ok(_) => {
27 // If wasi-experimental is not found, first check if we're running
28 // on .NET SDK 8.0. We can't even install that workload on older
29 // versions, and we don't support .NET 9.0 yet, so this helps to
30 // provide a nicer message than "Workload ID wasi-experimental is not recognized.".
31 let version = dotnet!("--version").read().unwrap_or_default();
32 if parse_major_version(&version) != Some(8) {
33 anyhow::bail!(concat!(
34 ".NET SDK 8.0 is required, but found {version}.\n",
35 "If you have multiple versions of .NET SDK installed, configure your project using https://learn.microsoft.com/en-us/dotnet/core/tools/global-json."
36 ));
37 }
38
39 // Finally, try to install the workload ourselves. On some systems
40 // this might require elevated privileges, so print a nice error
41 // message if it fails.
42 dotnet!(
43 "workload",
44 "install",
45 "wasi-experimental",
46 "--skip-manifest-update"
47 )
48 .stderr_capture()
49 .run()
50 .context(concat!(
51 "Couldn't install the required wasi-experimental workload.\n",
52 "You might need to install it manually by running `dotnet workload install wasi-experimental` with privileged rights."
53 ))?;
54 }
55 Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
56 anyhow::bail!("dotnet not found in PATH. Please install .NET SDK 8.0.")
57 }
58 Err(error) => anyhow::bail!("{error}"),
59 };
60
61 let config_name = if build_debug { "Debug" } else { "Release" };
62
63 // Ensure the project path exists.
64 fs::metadata(project_path).with_context(|| {
65 format!(
66 "The provided project path '{}' does not exist.",
67 project_path.to_str().unwrap()
68 )

Callers 1

buildFunction · 0.85

Calls 11

parse_major_versionFunction · 0.85
metadataFunction · 0.85
joinMethod · 0.80
allMethod · 0.80
iterMethod · 0.65
OkFunction · 0.50
readMethod · 0.45
containsMethod · 0.45
runMethod · 0.45
kindMethod · 0.45
anyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…