Compare commits

..

5 commits

19 changed files with 7629 additions and 19773 deletions

View file

@ -1,2 +0,0 @@
[unstable]
bindeps = true

6
.gitignore vendored
View file

@ -1,7 +1,7 @@
/target
.env
/config.toml
config.toml
.direnv
/target
/target-bin
target/
target-bin/
secrets/

1228
Cargo.lock generated

File diff suppressed because it is too large Load diff

25476
Cargo.nix

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,8 @@
[workspace]
members = [
"chir-rs-castore",
"chir-rs-client",
"chir-rs-castore", "chir-rs-client",
"chir-rs-config",
"chir-rs-db",
"chir-rs-fe",
"chir-rs-gemini",
"chir-rs-http",
"chir-rs-http-api",
@ -37,11 +35,7 @@ sentry = { version = "0.34.0", default-features = false, features = [
] }
sentry-eyre = "0.2.0"
sentry-tracing = { version = "0.34.0", features = ["backtrace"] }
tokio = { version = "1.41.1", features = [
"macros",
"rt-multi-thread",
"signal",
] }
tokio = { version = "1.41.1", features = ["macros", "rt-multi-thread", "signal"] }
tracing = "0.1.41"
tracing-error = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }
@ -100,3 +94,9 @@ codegen-units = 1
lto = true
debug = "full"
strip = "none"
[profile.dev.package."*"]
opt-level = 2
[profile.dev]
opt-level = 1

View file

@ -15,7 +15,6 @@ eyre = "0.6.12"
stretto = { version = "0.8.4", features = ["async"] }
tokio = { version = "1.41.1", features = ["fs"] }
tracing = "0.1.41"
[lints.rust]
deprecated-safe = "forbid"
elided_lifetimes_in_paths = "warn"

View file

@ -97,94 +97,100 @@ impl CaStore {
let string_id = lexicographic_base64::encode(id.to_be_bytes());
let source_fname = format!("temp/{string_id}");
/*info!("Starting multipart upload {id}");
let multipart_result = self
.client
.create_multipart_upload()
.bucket(&*self.bucket)
.key(&source_fname)
.send()
.await
.with_context(|| format!("Creating multipart request for Request ID{id}"))?;
let mut buf = BytesMut::with_capacity(16 * 1024 * 1024); // 16MiB byte buffer for the file
let mut buf = BytesMut::with_capacity(5_000_000);
reader.read_buf(&mut buf).await?;
let hasher = Arc::new(Mutex::new(Hasher::new()));
let mut i = 1;
let mut completed_multipart_upload_builder = CompletedMultipartUpload::builder();
loop {
buf.clear();
reader.read_buf(&mut buf).await.context("Reading chunk")?;
if buf.is_empty() {
break;
}
debug!("Uploading part {i} for multipart upload {id}");
let buf2 = buf.clone();
let hasher = Arc::clone(&hasher);
let hasher_job = spawn_blocking(move || {
hasher.blocking_lock().update_rayon(&buf2);
});
let part_upload_fut = self
let hash = if buf.len() >= 5_000_000 {
info!("Starting multipart upload {id}");
let multipart_result = self
.client
.upload_part()
.create_multipart_upload()
.bucket(&*self.bucket)
.key(&source_fname)
.set_upload_id(multipart_result.upload_id.clone())
.body(ByteStream::from(buf.to_vec()))
.part_number(i)
.send();
.send()
.await
.with_context(|| format!("Creating multipart request for Request ID{id}"))?;
let ((), part_upload_result) = try_join!(
async { hasher_job.await.context("Awaiting hasher job") },
async { part_upload_fut.await.context("Awaiting uploader job") }
)
.context("Awaiting job for chunk")?;
completed_multipart_upload_builder = completed_multipart_upload_builder.parts(
CompletedPart::builder()
.e_tag(part_upload_result.e_tag.unwrap_or_default())
let mut reader = buf.chain(reader);
let mut buf = BytesMut::with_capacity(16 * 1024 * 1024); // 16MiB byte buffer for the file
let hasher = Arc::new(Mutex::new(Hasher::new()));
let mut i = 1;
let mut completed_multipart_upload_builder = CompletedMultipartUpload::builder();
loop {
buf.clear();
reader.read_buf(&mut buf).await.context("Reading chunk")?;
if buf.is_empty() {
break;
}
debug!("Uploading part {i} for multipart upload {id}");
let buf2 = buf.clone();
let hasher = Arc::clone(&hasher);
let hasher_job = spawn_blocking(move || {
hasher.blocking_lock().update_rayon(&buf2);
});
let part_upload_fut = self
.client
.upload_part()
.bucket(&*self.bucket)
.key(&source_fname)
.set_upload_id(multipart_result.upload_id.clone())
.body(ByteStream::from(buf.to_vec()))
.part_number(i)
.build(),
);
i += 1;
}
.send();
debug!("Finalizing Multipart Upload {id}");
let ((), part_upload_result) = try_join!(
async { hasher_job.await.context("Awaiting hasher job") },
async { part_upload_fut.await.context("Awaiting uploader job") }
)
.context("Awaiting job for chunk")?;
completed_multipart_upload_builder = completed_multipart_upload_builder.parts(
CompletedPart::builder()
.e_tag(part_upload_result.e_tag.unwrap_or_default())
.part_number(i)
.build(),
);
i += 1;
}
let hash = hasher.lock().await.finalize();
self.client
.complete_multipart_upload()
.bucket(&*self.bucket)
.key(&source_fname)
.multipart_upload(completed_multipart_upload_builder.build())
.set_upload_id(multipart_result.upload_id)
.send()
.await
.context("Completing multipart upload")?;*/
debug!("Finalizing Multipart Upload {id}");
let hasher = Arc::new(Mutex::new(Hasher::new()));
let mut buf = Vec::new();
reader.read_to_end(&mut buf).await?;
let buf = Bytes::from(buf);
let buf2 = buf.clone();
let hasher2 = Arc::clone(&hasher);
spawn_blocking(move || {
hasher2.blocking_lock().update_rayon(&buf2);
})
.await?;
self.client
.put_object()
.bucket(&*self.bucket)
.key(&source_fname)
.body(ByteStream::from(buf.to_vec()))
.send()
.await
.context("Uploading file")?;
let hash = hasher.lock().await.finalize();
self.client
.complete_multipart_upload()
.bucket(&*self.bucket)
.key(&source_fname)
.multipart_upload(completed_multipart_upload_builder.build())
.set_upload_id(multipart_result.upload_id)
.send()
.await
.context("Completing multipart upload")?;
hash
} else {
let buf = Bytes::from(buf);
let buf2 = buf.clone();
let hasher2 = Arc::clone(&hasher);
spawn_blocking(move || {
hasher2.blocking_lock().update_rayon(&buf2);
})
.await?;
self.client
.put_object()
.bucket(&*self.bucket)
.key(&source_fname)
.body(ByteStream::from(buf.to_vec()))
.send()
.await
.context("Uploading file")?;
let hash = hasher.lock().await.finalize();
hasher.lock().await.finalize()
};
let target_fname = lexicographic_base64::encode(hash.as_bytes());

View file

@ -12,7 +12,11 @@ dotenvy = "0.15.7"
eyre = "0.6.12"
mime = "0.3.17"
mime_guess = "2.0.5"
reqwest = { version = "0.12.9", default-features = false, features = ["rustls-tls", "stream"] }
reqwest = { version = "0.12.9", default-features = false, features = [
"http2",
"rustls-tls",
"stream",
] }
tokio = { version = "1.41.1", features = ["fs", "macros", "rt-multi-thread"] }
tracing = "0.1.41"
tracing-subscriber = "0.3.19"

View file

@ -1,20 +1,22 @@
use std::{collections::HashSet, future::Future, path::Path, pin::Pin};
use std::{
collections::HashSet, future::Future, path::PathBuf, pin::Pin, sync::Arc, time::Duration,
};
use chir_rs_http_api::{
auth::{LoginRequest, PasetoToken, Scope},
errors::APIError,
};
use clap::{arg, Parser, Subcommand};
use eyre::{eyre, Context as _, OptionExt as _, Result};
use mime_guess::{Mime, MimeGuess};
use eyre::{eyre, Context as _, Result};
use mime_guess::MimeGuess;
use reqwest::Body;
use tokio::join;
use tokio::{sync::Mutex, task::JoinSet};
use tracing::{info, instrument};
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
#[arg(short, long, default_value = "http://localhost:5621/")]
#[arg(short, long, default_value = "https://lotte.chir.rs/")]
url: String,
#[command(subcommand)]
command: Command,
@ -42,14 +44,18 @@ enum Command {
},
}
async fn login(url: String, username: String, password: String) -> Result<()> {
async fn login(
client: Arc<reqwest::Client>,
url: String,
username: String,
password: String,
) -> Result<()> {
let request = LoginRequest {
username,
password,
scopes: HashSet::from([Scope::Full]),
};
let request = bincode::encode_to_vec(request, bincode::config::standard())?;
let client = reqwest::Client::new();
let res = client
.post(format!("{url}.api/auth/login"))
.header("Content-Type", "application/x+bincode")
@ -74,9 +80,13 @@ async fn login(url: String, username: String, password: String) -> Result<()> {
Ok(())
}
#[instrument(skip(source))]
async fn upload(url: String, source: impl AsRef<Path>, dest: String) -> Result<()> {
let client = reqwest::Client::new();
#[instrument(skip(client))]
async fn upload_inner(
client: Arc<reqwest::Client>,
url: String,
source: PathBuf,
dest: String,
) -> Result<bool> {
let token = std::env::var("CHIR_RS_TOKEN")?;
let file = tokio::fs::File::open(&source).await?;
let res = client
@ -92,18 +102,55 @@ async fn upload(url: String, source: impl AsRef<Path>, dest: String) -> Result<(
.body(Body::from(file))
.send()
.await?;
info!("Finished uploading {dest}");
if !res.status().is_success() {
let status = res.status();
if status.is_client_error() {
let response = res.bytes().await?;
let response: APIError =
bincode::decode_from_slice(&response, bincode::config::standard())?.0;
Err(response).with_context(|| format!("Uploading to {dest}"))?;
} else if status.is_server_error() {
let response = res.bytes().await?;
let response: APIError =
bincode::decode_from_slice(&response, bincode::config::standard())?.0;
println!("Server error updating {dest}: {response:?}");
return Ok(false);
}
info!("Updated {dest}.");
Ok(true)
}
#[instrument(skip(client))]
async fn upload(
client: Arc<reqwest::Client>,
url: String,
source: PathBuf,
dest: String,
) -> Result<()> {
loop {
if upload_inner(
Arc::clone(&client),
url.clone(),
source.clone(),
dest.clone(),
)
.await?
{
break;
}
println!("Uploading to {dest} failed. waiting 5s");
tokio::time::sleep(Duration::from_secs(5)).await;
}
Ok(())
}
#[instrument(skip(source))]
async fn upload_dir(url: String, source: impl AsRef<Path>, dest: String) -> Result<()> {
#[instrument(skip(client))]
async fn upload_dir(
client: Arc<reqwest::Client>,
futs: Arc<Mutex<JoinSet<Result<()>>>>,
url: String,
source: PathBuf,
dest: String,
) -> Result<()> {
let mut dir = tokio::fs::read_dir(source).await?;
while let Some(ent) = dir.next_entry().await? {
let file_type = ent.file_type().await?;
@ -117,18 +164,39 @@ async fn upload_dir(url: String, source: impl AsRef<Path>, dest: String) -> Resu
format!("{dest}/{file_name_str}")
};
if file_type.is_dir() {
let sub_fut: Pin<Box<dyn Future<Output = Result<()>>>> =
Box::pin(upload_dir(url.clone(), ent.path(), tgt));
sub_fut.await?;
let boxed: Pin<Box<dyn Future<Output = Result<()>>>> = Box::pin(upload_dir(
Arc::clone(&client),
Arc::clone(&futs),
url.clone(),
ent.path().to_path_buf(),
tgt,
));
boxed.await?;
continue;
}
if file_name_str == "index.html" {
if !dest.is_empty() {
upload(url.clone(), ent.path(), format!("{dest}/")).await?;
futs.lock().await.spawn(upload(
Arc::clone(&client),
url.clone(),
ent.path().to_path_buf(),
format!("{dest}/"),
));
}
upload(url.clone(), ent.path(), dest.clone()).await?;
futs.lock().await.spawn(upload(
Arc::clone(&client),
url.clone(),
ent.path().to_path_buf(),
dest.clone(),
));
}
upload(url.clone(), ent.path(), tgt).await?;
futs.lock().await.spawn(upload(
Arc::clone(&client),
url.clone(),
ent.path().to_path_buf(),
tgt,
));
}
Ok(())
}
@ -139,11 +207,22 @@ async fn main() -> Result<()> {
dotenvy::dotenv().ok();
tracing_subscriber::fmt::init();
let matches = Args::parse();
let client = Arc::new(reqwest::Client::new());
match matches.command {
Command::Login { username, password } => login(matches.url, username, password).await?,
Command::Upload { source, dest } => upload(matches.url, source, dest).await?,
Command::UploadDir { source, dest } => upload_dir(matches.url, source, dest).await?,
Command::Login { username, password } => {
login(client, matches.url, username, password).await?
}
Command::Upload { source, dest } => {
upload(client, matches.url, source.into(), dest).await?
}
Command::UploadDir { source, dest } => {
let futs = Arc::new(Mutex::new(JoinSet::new()));
upload_dir(client, Arc::clone(&futs), matches.url, source.into(), dest).await?;
while let Some(v) = futs.lock().await.join_next().await {
v??;
}
}
}
Ok(())

View file

@ -1,74 +0,0 @@
[package]
name = "chir-rs-fe"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
bincode = "2.0.0-rc.3"
chir-rs-http-api = { version = "0.1.0", path = "../chir-rs-http-api" }
console_error_panic_hook = "0.1.7"
eyre = "0.6.12"
gloo-net = "0.6.0"
gloo-storage = "0.3.0"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
unicode-normalization = "0.1.24"
wasm-bindgen = "=0.2.99"
wasm-tracing = "0.2.1"
web-sys = { version = "0.3.76", features = ["HtmlInputElement"] }
yew = { version = "0.21.0", features = ["csr"] }
yew-router = "0.18.0"
[build-dependencies]
wasm-bindgen-cli = { version = "=0.2.99", artifact = "bin" }
[lints.rust]
deprecated-safe = "forbid"
elided_lifetimes_in_paths = "warn"
explicit_outlives_requirements = "warn"
impl-trait-overcaptures = "warn"
keyword-idents-2024 = "forbid"
let-underscore-drop = "warn"
macro-use-extern-crate = "deny"
meta-variable-misuse = "deny"
missing-abi = "forbid"
missing-copy-implementations = "warn"
missing-debug-implementations = "deny"
missing-docs = "warn"
missing-unsafe-on-extern = "deny"
non-local-definitions = "warn"
redundant-lifetimes = "warn"
single-use-lifetimes = "warn"
trivial-casts = "warn"
trivial-numeric-casts = "warn"
unit-bindings = "deny"
unnameable-types = "warn"
unreachable-pub = "warn"
unsafe-code = "forbid"
unused-crate-dependencies = "warn"
unused-extern-crates = "warn"
unused-import-braces = "warn"
unused-lifetimes = "warn"
unused-macro-rules = "warn"
unused-qualifications = "warn"
variant-size-differences = "warn"
[lints.clippy]
nursery = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
module-name-repetitions = "allow"
alloc-instead-of-core = "warn"
allow-attributes-without-reason = "deny"
assertions-on-result-states = "forbid"
clone-on-ref-ptr = "warn"
empty-drop = "warn"
expect-used = "deny"
inline-asm-x86-att-syntax = "forbid"
missing-docs-in-private-items = "warn"
panic = "deny"
panic-in-result-fn = "forbid"
rc-buffer = "warn"
rc-mutex = "deny"

View file

@ -1,17 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<script type="module">
import init from './chir_rs_fe.js';
async function run() {
await init();
}
run();
</script>
<link rel="stylesheet" href="/css/style.css">
</head>
<body></body>
</html>

View file

@ -1,19 +0,0 @@
//! Homepage
use gloo_storage::{SessionStorage, Storage};
use yew::prelude::*;
use yew_router::prelude::*;
use crate::Route;
/// Render the home page of the admin page
pub fn home_page() -> Html {
SessionStorage::get::<String>("api").map_or_else(
|_| {
html! {
<Redirect<Route> to={Route::Login} />
}
},
|api_key| html! {<p>{api_key}</p>},
)
}

View file

@ -1,76 +0,0 @@
//! Management frontend for chir.rs
use std::future::Future;
use tracing::{error, instrument};
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _};
use wasm_bindgen::prelude::*;
use wasm_tracing::{WASMLayer, WASMLayerConfigBuilder};
use yew::{platform::spawn_local, prelude::*};
use yew_router::prelude::*;
pub mod home;
pub mod login;
#[instrument(skip(fut))]
pub fn spawn<F>(fut: F)
where
F: Future<Output = eyre::Result<()>> + 'static,
{
spawn_local(async move {
if let Err(e) = fut.await {
error!("Failed to run async closure: {e:?}");
}
});
}
/// Routes defined by this SPA
#[derive(Clone, Routable, PartialEq)]
enum Route {
/// Home page
#[at("/")]
Home,
/// Login page
#[at("/login")]
Login,
}
/// Render the main site content
#[allow(clippy::needless_pass_by_value, reason = "API reasons")]
fn switch(routes: Route) -> Html {
match routes {
Route::Home => home::home_page(),
Route::Login => html! {
<login::Login />
},
}
}
#[function_component(App)]
fn app() -> Html {
html! {
<div class="container">
<header>
<hgroup>
<h1> {"Lottes Attic"} </h1>
<p> {"Super secret raccministrator portal :3c "} </p>
</hgroup>
</header>
<main id="main" role="main">
<HashRouter>
<Switch<Route> render={switch} />
</HashRouter>
</main>
</div>
}
}
#[wasm_bindgen(start)]
fn main() {
console_error_panic_hook::set_once();
tracing_subscriber::registry()
.with(WASMLayer::new(WASMLayerConfigBuilder::new().build()))
.init();
yew::Renderer::<App>::new().render();
}

View file

@ -1,100 +0,0 @@
//! Login screen
use std::collections::HashSet;
use chir_rs_http_api::{
auth::{LoginRequest, PasetoToken, Scope},
errors::APIError,
};
use eyre::Context;
use gloo_net::http::Request;
use gloo_storage::{SessionStorage, Storage as _};
use tracing::info;
use unicode_normalization::UnicodeNormalization;
use wasm_bindgen::JsCast as _;
use web_sys::HtmlInputElement;
use yew::prelude::*;
use yew_router::hooks::use_navigator;
use crate::{spawn, Route};
/// Login view
#[function_component]
pub fn Login() -> Html {
let navigator = use_navigator().unwrap();
let username_handle = use_state(String::default);
let username = username_handle.clone();
let password_handle = use_state(String::default);
let password = password_handle.clone();
let on_username_input = Callback::from(move |e: InputEvent| {
let target = e.target();
let input = target.and_then(|t| t.dyn_into::<HtmlInputElement>().ok());
if let Some(input) = input {
username.set(input.value());
}
});
let on_password_input = Callback::from(move |e: InputEvent| {
let target = e.target();
let input = target.and_then(|t| t.dyn_into::<HtmlInputElement>().ok());
if let Some(input) = input {
password.set(input.value());
}
});
let onsubmit = Callback::from(move |e: SubmitEvent| {
let navigator = navigator.clone();
e.prevent_default();
let username = username_handle.trim();
let password = password_handle.trim().nfkc().collect::<String>();
let request = LoginRequest {
username: username.to_string(),
password,
scopes: HashSet::from([Scope::Full]),
};
spawn(async move {
let req_body = bincode::encode_to_vec(request, bincode::config::standard())
.context("Encoding login request")?;
let resp = Request::post("/.api/auth/login")
.header("Content-Type", "application/x+bincode")
.header("Accept", "application/x+bincode")
.body(req_body)
.context("Setting body for login request")?
.send()
.await
.context("Sending request for login request")?;
let status = resp.status();
let resp_body = resp
.binary()
.await
.context("Loading server response for login request")?;
if status >= 400 {
let error: APIError =
bincode::decode_from_slice(&resp_body, bincode::config::standard())
.context("Decoding error response")?
.0;
Err(error).context("While logging in")?;
} else {
let token: PasetoToken =
bincode::decode_from_slice(&resp_body, bincode::config::standard())
.context("Decoding success response")?
.0;
SessionStorage::set("api", token.to_paseto());
}
navigator.replace(&Route::Home);
Ok(())
});
info!("{e:?}");
});
html! {
<form accept-charset="utf-8" onsubmit={onsubmit}>
<label for="username">{"Username:"}</label>
<input id="username" type="text" placeholder="https://lotte.chir.rs/" oninput={on_username_input} />
<label for="password">{"Password:"}</label>
<input id="password" type="password" placeholder="●●●●●●●●●●●●●●●●" oninput={on_password_input} />
<input type="submit" value="Submit"/>
</form>
}
}

View file

@ -22,9 +22,11 @@ chrono = "0.4.38"
eyre = "0.6.12"
futures = "0.3.31"
mime = "0.3.17"
rusty_paseto = { version = "0.7.1", default-features = false, features = ["batteries_included", "v4_local"] }
rusty_paseto = { version = "0.7.1", default-features = false, features = [
"batteries_included",
"v4_local",
] }
sentry-tower = { version = "0.34.0", features = ["axum", "axum-matched-path"] }
serde = { version = "1.0.215", features = ["derive"] }
tokio = { version = "1.41.1", features = ["fs", "net"] }
tokio-util = { version = "0.7.13", features = ["compat"] }
tower-http = { version = "0.6.2", features = ["trace"] }

View file

@ -2,7 +2,7 @@
use axum::{
body::Body,
extract::{Query, State},
extract::State,
http::{
header::{ACCEPT, CACHE_CONTROL, CONTENT_LENGTH, CONTENT_TYPE, ETAG, IF_NONE_MATCH},
HeaderMap, Request, StatusCode, Uri,
@ -15,7 +15,6 @@ use chir_rs_misc::lexicographic_base64;
use eyre::Context as _;
use futures::TryStreamExt;
use mime::MimeIter;
use serde::Deserialize;
use tokio_util::compat::FuturesAsyncReadCompatExt as _;
use tracing::{debug, error, info};

View file

@ -14,11 +14,11 @@
]
},
"locked": {
"lastModified": 1733731208,
"narHash": "sha256-s9O/KIBhKOS49VmYJIBEiCrLK5hocJLKuvAkwAoELLQ=",
"lastModified": 1726552619,
"narHash": "sha256-ytTBILVMnRZYvjiLYz+J6IFf/TOXdGuP6RDesMx9qgA=",
"owner": "DarkKirb",
"repo": "cargo2nix",
"rev": "37f356e1ba56e591550647c86039ffb0ca0c2201",
"rev": "baa12124e2de09e1cbbdac320f14809fa55af1a2",
"type": "github"
},
"original": {
@ -78,11 +78,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1733132332,
"narHash": "sha256-8DTh3irBPko0ooHaeGJ5kPwBD8mOwiMX4eBjFuicLsA=",
"lastModified": 1733682815,
"narHash": "sha256-8DFHnrHprF8u95VOFgMAgJe2OBD70pd1g0NFtIEElAY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b9ffe0d2ef589f4d75a62f908f00dfd6344b6b6e",
"rev": "73b9f2d20bea97d5bd6c8158f3a388ef40ac97c5",
"type": "github"
},
"original": {
@ -128,11 +128,11 @@
]
},
"locked": {
"lastModified": 1733106880,
"narHash": "sha256-aJmAIjZfWfPSWSExwrYBLRgXVvgF5LP1vaeUGOOIQ98=",
"lastModified": 1733625333,
"narHash": "sha256-tIML2axjm4AnlKP29upVJxzBpj4Cy4ak+PKonqQtXmc=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "e66c0d43abf5bdefb664c3583ca8994983c332ae",
"rev": "430c8b054e45ea44fd2c9521a378306ada507a6c",
"type": "github"
},
"original": {

View file

@ -59,38 +59,11 @@
pkgs = import nixpkgs {
inherit system overlays;
};
pkgs-wasm32 = import nixpkgs {
inherit system overlays;
crossSystem = {
system = "wasm32-wasi";
useLLVM = true;
};
};
rustPkgs = pkgs.rustBuilder.makePackageSet {
packageFun = import ./Cargo.nix;
rustChannel = "nightly";
rustChannel = "stable";
rustVersion = "latest";
packageOverrides = pkgs: pkgs.rustBuilder.overrides.all;
extraConfigToml = ''
[unstable]
bindeps = true
'';
};
rustPkgs-wasm32 = pkgs-wasm32.rustBuilder.makePackageSet {
packageFun = import ./Cargo.nix;
rustChannel = "nightly";
rustVersion = "latest";
packageOverrides = pkgs: pkgs.rustBuilder.overrides.all;
target = "wasm32-unknown-unknown";
hostPlatform = pkgs-wasm32.stdenv.hostPlatform // {
parsed = pkgs-wasm32.stdenv.hostPlatform.parsed // {
kernel.name = "unknown";
};
};
extraConfigToml = ''
[unstable]
bindeps = true
'';
};
in
rec {
@ -98,13 +71,6 @@
with pkgs;
mkShell {
buildInputs = [
(rust-bin.selectLatestNightlyWith (
toolchain:
toolchain.default.override {
extensions = [ "rust-src" ];
targets = [ "wasm32-unknown-unknown" ];
}
))
cargo2nix.packages.${system}.cargo2nix
rustfilt
gdb
@ -113,39 +79,9 @@
sqlite
treefmt
nixfmt-rfc-style
wabt
trunk
(rustPkgs."registry+https://github.com/rust-lang/crates.io-index".wasm-bindgen-cli."0.2.99" { })
binaryen
];
};
packages =
(pkgs.lib.mapAttrs (_: v: (v { }).overrideAttrs { dontStrip = true; }) rustPkgs.workspace)
// {
chir-rs-fe =
let
chir-rs-fe = rustPkgs-wasm32.workspace.chir-rs-fe { };
wasm-bindgen-cli =
rustPkgs."registry+https://github.com/rust-lang/crates.io-index".wasm-bindgen-cli."0.2.99"
{ };
in
pkgs.stdenvNoCC.mkDerivation {
inherit (chir-rs-fe) name version;
src = chir-rs-fe.out;
dontUnpack = true;
dontBuild = true;
nativeBuildInputs = [
wasm-bindgen-cli
pkgs.binaryen
];
installPhase = ''
mkdir $out
wasm-opt $src/lib/chir_rs_fe.wasm -o chir_rs_fe.wasm
wasm-bindgen chir_rs_fe.wasm --out-dir $out --target web
cp ${./chir-rs-fe/index.html} $out/index.html
'';
};
};
packages = pkgs.lib.mapAttrs (_: v: (v { }).overrideAttrs { dontStrip = true; }) rustPkgs.workspace;
nixosModules.default = import ./nixos {
inherit inputs system;
};

1
result
View file

@ -1 +0,0 @@
/nix/store/navjjbwfm21p9z8c9f62zpislxhbn1xb-chir-rs-fe