summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorojacobson <ojacobson@noreply.codeberg.org>2025-05-30 21:12:31 +0200
committerojacobson <ojacobson@noreply.codeberg.org>2025-05-30 21:12:31 +0200
commitebb6a0bff2dd14afec3f0bb1db556797ac2f34ab (patch)
treebdec2f8051ff699553439a2b71c60de03bb5cac7
parent79e0dd78e062c3258fa911b99c8f4156f134f877 (diff)
parent4734dfca27bf9d498f3e9b3e42c7a5c01a188237 (diff)
Build the Sveltekit UI into Cargo's OUT_DIR.
This has a couple of material consequences: * It will be (much) easier to reorganize the source tree, as the path to the output is no longer relative to where the config files are when building the final binary. If we do decide to move `ui` into its own child crate, we won't have to make a bunch of (very similar) changes to the Svelte build process at that time. * There is less chance of a stale build contaminating a new one, since changes to the crate change the project hash in `OUT_DIR`. For example, while working on this change, `OUT_DIR` was at various points: * `target/debug/build/pilcrow-7cfeef3536ddd3e7/out` * `target/debug/build/pilcrow-09d4ddbc12bef36b/out` * `target/release/build/pilcrow-070d373bd5f850a1` This may use more space on disk, but it's all reclaimable with `cargo clean` and Rust is _far_ more profligate with disk space than Svelte will ever be. * It's more consistent with Cargo's expectations around generated source files, and thus potentially easier to onboard Rust developers into. Merges prop/ui-build-to-cargo-output into main.
-rw-r--r--Cargo.lock60
-rw-r--r--Cargo.toml2
-rw-r--r--src/ui/assets.rs2
-rw-r--r--svelte.config.js13
4 files changed, 72 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b6ea4d9..65cacbd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
-version = 3
+version = 4
[[package]]
name = "addr2line"
@@ -481,6 +481,27 @@ dependencies = [
]
[[package]]
+name = "dirs"
+version = "6.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
+dependencies = [
+ "dirs-sys",
+]
+
+[[package]]
+name = "dirs-sys"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
+dependencies = [
+ "libc",
+ "option-ext",
+ "redox_users",
+ "windows-sys 0.59.0",
+]
+
+[[package]]
name = "displaydoc"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1157,6 +1178,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa"
[[package]]
+name = "libredox"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
+dependencies = [
+ "bitflags",
+ "libc",
+]
+
+[[package]]
name = "libsqlite3-sys"
version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1312,6 +1343,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
[[package]]
+name = "option-ext"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
+
+[[package]]
name = "parking"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1532,6 +1569,17 @@ dependencies = [
]
[[package]]
+name = "redox_users"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b"
+dependencies = [
+ "getrandom 0.2.15",
+ "libredox",
+ "thiserror",
+]
+
+[[package]]
name = "rsa"
version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1585,6 +1633,7 @@ dependencies = [
"proc-macro2",
"quote",
"rust-embed-utils",
+ "shellexpand",
"syn",
"walkdir",
]
@@ -1735,6 +1784,15 @@ dependencies = [
]
[[package]]
+name = "shellexpand"
+version = "3.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8b1fdf65dd6331831494dd616b30351c38e96e45921a27745cf98490458b90bb"
+dependencies = [
+ "dirs",
+]
+
+[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 10e6adb..82693e3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -38,7 +38,7 @@ rand_core = { version = "0.6.4", features = ["getrandom"] }
# Pinned to maintain libsqlite3 version match between this and sqlx. See also:
# <https://docs.rs/sqlx/latest/sqlx/sqlite/index.html>
rusqlite = { version = "=0.32.1", features = ["backup"] }
-rust-embed = "8.5.0"
+rust-embed = { version = "8.5.0", features = ["interpolate-folder-path"] }
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.138"
# Pinned to maintain libsqlite3 version match between this and rusqlite. See
diff --git a/src/ui/assets.rs b/src/ui/assets.rs
index 642679b..0ca9593 100644
--- a/src/ui/assets.rs
+++ b/src/ui/assets.rs
@@ -9,7 +9,7 @@ use super::{error::NotFound, mime};
use crate::error::Internal;
#[derive(rust_embed::Embed)]
-#[folder = "target/ui"]
+#[folder = "$OUT_DIR/ui"]
pub struct Assets;
impl Assets {
diff --git a/svelte.config.js b/svelte.config.js
index 5e64863..dbef20d 100644
--- a/svelte.config.js
+++ b/svelte.config.js
@@ -1,11 +1,20 @@
+import path from 'node:path';
+import process from 'node:process';
import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
+// OUT_DIR is set by Cargo at build time:
+// <https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts>
+//
+// When we're building through `vite` directly, it will not be set; we use "target" as a generic
+// output directory to keep all the build products in one place.
+const outDir = process.env['OUT_DIR'] ?? 'target';
+
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter({
- pages: 'target/ui',
+ pages: path.join(outDir, 'ui'),
fallback: 'index.html',
}),
files: {
@@ -22,7 +31,7 @@ const config = {
appTemplate: 'ui/app.html',
errorTemplate: 'ui/error.html',
},
- outDir: 'target/svelte-kit',
+ outDir: path.join(outDir, 'svelte-kit'),
},
preprocess: vitePreprocess(),
};