mirror of
https://github.com/ipetkov/crane.git
synced 2024-10-04 01:37:57 +03:00
Trunk support (#299)
[Trunk](https://trunkrs.dev) is a tool that allow you to build web apps using Rust and webassembly, including compiling scss, and distributing other assets. Adds `craneLib.buildTrunkPackage`, a function that builds a Trunk project returning a directory with the resulting dist files for that project --------- Co-authored-by: Ivan Petkov <ivanppetkov@gmail.com>
This commit is contained in:
parent
54b63c8eae
commit
db21a44eb0
@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
* Added support for the [Trunk](https://trunkrs.dev) wasm app build tool
|
||||
|
||||
### [0.12.1] - 2023-04-10
|
||||
|
||||
### Changed
|
||||
|
@ -23,6 +23,7 @@ A [Nix] library for building [cargo] projects.
|
||||
* [cargo-audit] for vulnerability scanning
|
||||
* [cargo-nextest] a next-generation test runner
|
||||
* [cargo-tarpaulin] for code coverage
|
||||
* [trunk] for wasm frontend apps
|
||||
|
||||
## Getting Started
|
||||
|
||||
@ -72,3 +73,4 @@ conditions.
|
||||
[Nix]: https://nixos.org/
|
||||
[rustfmt]: https://github.com/rust-lang/rustfmt
|
||||
[Semantic Versioning]: http://semver.org/spec/v2.0.0.html
|
||||
[Trunk]: https://trunkrs.dev/
|
||||
|
@ -414,6 +414,10 @@ in
|
||||
smokeWorkspace = self.smoke [ "print" ] self.workspace;
|
||||
smokeWorkspaceRoot = self.smoke [ "print" ] self.workspaceRoot;
|
||||
|
||||
trunk = callPackage ./trunk.nix {
|
||||
inherit myLib;
|
||||
};
|
||||
|
||||
vendorCargoDeps =
|
||||
let
|
||||
src = ./workspace;
|
||||
|
35
checks/trunk.nix
Normal file
35
checks/trunk.nix
Normal file
@ -0,0 +1,35 @@
|
||||
{ pkgs
|
||||
, myLib
|
||||
, runCommand
|
||||
}:
|
||||
|
||||
let
|
||||
wasmToolchain = pkgs.rust-bin.stable.latest.minimal.override {
|
||||
targets = [ "wasm32-unknown-unknown" ];
|
||||
};
|
||||
|
||||
myLibWasm = myLib.overrideToolchain wasmToolchain;
|
||||
|
||||
defaultArgs = {
|
||||
src = ./trunk;
|
||||
doCheck = false;
|
||||
};
|
||||
|
||||
# default build
|
||||
cargoArtifacts = myLibWasm.buildDepsOnly (defaultArgs // {
|
||||
cargoExtraArgs = "--target=wasm32-unknown-unknown";
|
||||
});
|
||||
trunkSimple = myLibWasm.buildTrunkPackage (defaultArgs // {
|
||||
inherit cargoArtifacts;
|
||||
pname = "trunk-simple";
|
||||
});
|
||||
|
||||
trunkSimpleNoArtifacts = myLibWasm.buildTrunkPackage (defaultArgs // {
|
||||
pname = "trunk-simple-no-artifacts";
|
||||
});
|
||||
in
|
||||
runCommand "trunkTests" { } ''
|
||||
test -f ${trunkSimple}/*.wasm
|
||||
test -f ${trunkSimpleNoArtifacts}/*.wasm
|
||||
mkdir -p $out
|
||||
''
|
156
checks/trunk/Cargo.lock
generated
Normal file
156
checks/trunk/Cargo.lock
generated
Normal file
@ -0,0 +1,156 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "console_log"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be8aed40e4edbf4d3b4431ab260b63fdc40f5780a4766824329ea0f1eefe3c0f"
|
||||
dependencies = [
|
||||
"log",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.56"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "trunk"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"console_log",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
8
checks/trunk/Cargo.toml
Normal file
8
checks/trunk/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "trunk"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
console_log = "1.0.0"
|
||||
log = "0.4.17"
|
7
checks/trunk/index.html
Normal file
7
checks/trunk/index.html
Normal file
@ -0,0 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Trunk App</title>
|
||||
</head>
|
||||
</html>
|
4
checks/trunk/src/main.rs
Normal file
4
checks/trunk/src/main.rs
Normal file
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
console_log::init().unwrap();
|
||||
log::debug!("Hi, this can run on the browser");
|
||||
}
|
52
docs/API.md
52
docs/API.md
@ -226,6 +226,58 @@ The following hooks are automatically added as native build inputs:
|
||||
* `jq`
|
||||
* `removeReferencesToVendoredSourcesHook`
|
||||
|
||||
### `craneLib.buildTrunkPackage`
|
||||
`buildTrunkPackage :: set -> drv`
|
||||
|
||||
Create a derivation which will build a distributable directory for a WASM application.
|
||||
|
||||
Except where noted below, all derivation attributes are delegated to
|
||||
`mkCargoDerivation`, and can be used to influence its behavior.
|
||||
|
||||
#### Optional attributes
|
||||
* `buildPhaseCargoCommand`: A command to run during the derivation's build
|
||||
phase. Pre and post build hooks will automatically be run.
|
||||
- Default value: `trunk build` will be invoked along with `trunkExtraArgs`,
|
||||
`trunkExtraBuildArgs`, and `trunkIndexpath` passed in. If `$CARGO_PROFILE`
|
||||
is set to `release` then the `--release` flag will also be set for the build
|
||||
* `cargoArtifacts`: A path (or derivation) which contains an existing cargo
|
||||
`target` directory, which will be reused at the start of the derivation.
|
||||
Useful for caching incremental cargo builds.
|
||||
- Default value: the result of `buildDepsOnly` after applying the arguments
|
||||
set (with the respective default values).
|
||||
- `CARGO_BUILD_TARGET` will be set to `"wasm32-unknown-unknown"` if not specified.
|
||||
- `doCheck` will be set to `false` if not specified.
|
||||
- `installCargoArtifactsMode` will be set to `"use-zstd"` if not specified.
|
||||
- `installPhase` and `installPhaseCommand` will be removed (in favor of their
|
||||
default values provided by `buildDepsOnly`)
|
||||
* `installPhaseCommand`: the command(s) which are expected to install the
|
||||
derivation's outputs.
|
||||
- Default value: will install trunk's `dist` output directory
|
||||
* `trunkExtraArgs` pass additional arguments to `trunk`
|
||||
- Default value: `""`
|
||||
* `trunkExtraBuildArgs` pass additional arguments to `trunk build`
|
||||
- Default value: `""`
|
||||
* `trunkIndexPath` A path to the index.html of your trunk project
|
||||
- Default value: `"./index.html"`
|
||||
|
||||
|
||||
#### Remove attributes
|
||||
The following attributes will be removed before being lowered to
|
||||
`mkCargoDerivation`. If you absolutely need these attributes present as
|
||||
environment variables during the build, you can bring them back via
|
||||
`.overrideAttrs`.
|
||||
|
||||
* `trunkExtraArgs`
|
||||
* `trunkExtraBuildArgs`
|
||||
* `trunkIndexPath`
|
||||
|
||||
#### Native build dependencies and included hooks
|
||||
The following hooks are automatically added as native build inputs:
|
||||
* `binaryen`
|
||||
* `nodePackages.sass`
|
||||
* `trunk`
|
||||
* `wasm-bindgen-cli`
|
||||
|
||||
### `craneLib.cargoAudit`
|
||||
`cargoAudit :: set -> drv`
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
* [Cross compiling](./examples/cross-rust-overlay.md)
|
||||
* [Cross compiling with musl](./examples/cross-musl.md)
|
||||
* [Cross compiling to windows](./examples/cross-windows.md)
|
||||
* [Building Trunk projects](./examples/trunk.md)
|
||||
* [Workspace with Trunk](./examples/trunk-workspace.md)
|
||||
* [Source filtering](./source-filtering.md)
|
||||
* [Local development](./local_development.md)
|
||||
* [Custom cargo commands](./custom_cargo_commands.md)
|
||||
|
20
docs/examples/trunk-workspace.md
Normal file
20
docs/examples/trunk-workspace.md
Normal file
@ -0,0 +1,20 @@
|
||||
[Trunk](https://trunkrs.dev) is a tool that allow you to build web apps using Rust and webassembly, including compiling scss, and distributing other assets.
|
||||
It can be used in conjunction with any of Rust's web frameworks for the development of full stack web applications.
|
||||
|
||||
In this example we have a workspace with three members:
|
||||
|
||||
* client: a Yew application compiled using Trunk
|
||||
* server: a Axum server built using Cargo
|
||||
* shared: a library that contains types to be imported in both the client and server
|
||||
|
||||
Quick-start a Trunk+Server project with
|
||||
|
||||
```sh
|
||||
nix flake init -t github:ipetkov/crane#trunk-workspace
|
||||
```
|
||||
|
||||
Alternatively, copy and paste the following `flake.nix` and modify it to build your workspace's packages:
|
||||
|
||||
```nix
|
||||
{{#include ../../examples/trunk-workspace/flake.nix}}
|
||||
```
|
19
docs/examples/trunk.md
Normal file
19
docs/examples/trunk.md
Normal file
@ -0,0 +1,19 @@
|
||||
[Trunk](https://trunkrs.dev) is a tool that allow you to build web apps using Rust and webassembly, including compiling scss, and distributing other assets.
|
||||
|
||||
Being a more specialized tool, it comes with some constraints that must be noted when using it in combination with crane:
|
||||
|
||||
* Your Toolchain must have the `wasm32-unknown-unknown` target installed (See: [Custom toolchain](../custom-toolchain.md))
|
||||
* For `craneLib.buildDepsOnly` to work you will need to set the build target (See: [API Reference](../API.md#libbuilddepsonly))
|
||||
* `craneLib.filterCargoSources` will remove html, css, your assets folder, so you need to modify the source filtering function (See: [Source filtering](../source-filtering.md))
|
||||
|
||||
Quick-start a Trunk project with
|
||||
|
||||
```sh
|
||||
nix flake init -t github:ipetkov/crane#trunk
|
||||
```
|
||||
|
||||
Alternatively, copy and paste the following `flake.nix`:
|
||||
|
||||
```nix
|
||||
{{#include ../../examples/trunk/flake.nix}}
|
||||
```
|
@ -20,6 +20,12 @@ nix flake init -t github:ipetkov/crane#cross-rust-overlay
|
||||
|
||||
# For statically linked binaries using musl
|
||||
nix flake init -t github:ipetkov/crane#cross-musl
|
||||
|
||||
# If you are building a WASM webapp with trunk
|
||||
nix flake init -t github:ipetkov/crane#trunk
|
||||
|
||||
# If you are building a workspace with trunk member
|
||||
nix flake init -t github:ipetkov/crane#trunk-workspace
|
||||
```
|
||||
|
||||
For an even more lean, no frills set up, create a `flake.nix` file with the
|
||||
|
1
examples/trunk-workspace/.gitignore
vendored
Normal file
1
examples/trunk-workspace/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
client/dist
|
1481
examples/trunk-workspace/Cargo.lock
generated
Normal file
1481
examples/trunk-workspace/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
6
examples/trunk-workspace/Cargo.toml
Normal file
6
examples/trunk-workspace/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"shared",
|
||||
"client",
|
||||
"server",
|
||||
]
|
11
examples/trunk-workspace/client/Cargo.toml
Normal file
11
examples/trunk-workspace/client/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "client"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
gloo = "0.8.0"
|
||||
shared = { version = "0.1.0", path = "../shared" }
|
||||
yew = { version = "0.20", features = ["csr"] }
|
7
examples/trunk-workspace/client/index.html
Normal file
7
examples/trunk-workspace/client/index.html
Normal file
@ -0,0 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Trunk App</title>
|
||||
</head>
|
||||
</html>
|
47
examples/trunk-workspace/client/src/main.rs
Normal file
47
examples/trunk-workspace/client/src/main.rs
Normal file
@ -0,0 +1,47 @@
|
||||
use gloo::net;
|
||||
use yew::prelude::*;
|
||||
|
||||
use shared::Post;
|
||||
|
||||
async fn request_posts() -> Vec<Post> {
|
||||
net::http::Request::get("http://localhost:8000/posts")
|
||||
.send()
|
||||
.await
|
||||
.expect("Failed to connect with server, is it runnig at localhost:8000?")
|
||||
.json()
|
||||
.await
|
||||
.expect("Received invalid response from server")
|
||||
}
|
||||
|
||||
struct AppStruct(Vec<Post>);
|
||||
|
||||
impl Component for AppStruct {
|
||||
type Message = Vec<Post>;
|
||||
type Properties = ();
|
||||
|
||||
fn create(ctx: &Context<Self>) -> Self {
|
||||
ctx.link().send_future(request_posts());
|
||||
Self(Default::default())
|
||||
}
|
||||
|
||||
fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
|
||||
self.0 = msg;
|
||||
true
|
||||
}
|
||||
|
||||
fn view(&self, _ctx: &Context<Self>) -> Html {
|
||||
html! {
|
||||
<ul>
|
||||
{for self.0.iter().map(|post| html! {
|
||||
<li>
|
||||
{format!("{} by {}", post.title, post.author_name)}
|
||||
</li>
|
||||
})}
|
||||
</ul>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
yew::Renderer::<AppStruct>::new().render();
|
||||
}
|
146
examples/trunk-workspace/flake.nix
Normal file
146
examples/trunk-workspace/flake.nix
Normal file
@ -0,0 +1,146 @@
|
||||
{
|
||||
description = "Build a cargo project";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
|
||||
crane = {
|
||||
url = "github:ipetkov/crane";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs = {
|
||||
nixpkgs.follows = "nixpkgs";
|
||||
flake-utils.follows = "flake-utils";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ (import rust-overlay) ];
|
||||
};
|
||||
|
||||
inherit (pkgs) lib;
|
||||
|
||||
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||
# Set the build targets supported by the toolchain,
|
||||
# wasm32-unknown-unknown is required for trunk.
|
||||
targets = [ "wasm32-unknown-unknown" ];
|
||||
};
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
||||
|
||||
# When filtering sources, we want to allow assets other than .rs files
|
||||
src = lib.cleanSourceWith {
|
||||
src = ./.; # The original, unfiltered source
|
||||
filter = path: type:
|
||||
(lib.hasSuffix "\.html" path) ||
|
||||
(lib.hasSuffix "\.scss" path) ||
|
||||
# Example of a folder for images, icons, etc
|
||||
(lib.hasInfix "/assets/" path) ||
|
||||
# Default filter from crane (allow .rs files)
|
||||
(craneLib.filterCargoSources path type)
|
||||
;
|
||||
};
|
||||
|
||||
|
||||
# Arguments to be used by both the client and the server
|
||||
# When building a workspace with crane, it's a good idea
|
||||
# to set "pname" and "version".
|
||||
commonArgs = {
|
||||
inherit src;
|
||||
pname = "trunk-workspace";
|
||||
version = "0.1.0";
|
||||
};
|
||||
|
||||
# Native packages
|
||||
|
||||
# We can avoid building our client's dependencies for the native target.
|
||||
nativeArgs = commonArgs // {
|
||||
pname = "trunk-workspace-native";
|
||||
cargoExtraArgs = "--workspace --exclude=client";
|
||||
};
|
||||
|
||||
# Build *just* the cargo dependencies, so we can reuse
|
||||
# all of that work (e.g. via cachix) when running in CI
|
||||
cargoArtifacts = craneLib.buildDepsOnly nativeArgs;
|
||||
|
||||
# Simple JSON API that can be queried by the client
|
||||
myServer = craneLib.buildPackage (nativeArgs // {
|
||||
inherit cargoArtifacts;
|
||||
# The server needs to know where the client's dist dir is to
|
||||
# serve it, so we pass it as an environment variable at build time
|
||||
CLIENT_DIST = myClient;
|
||||
});
|
||||
|
||||
# Wasm packages
|
||||
|
||||
# it's not possible to build the server on the
|
||||
# wasm32 target, so we only build the client.
|
||||
wasmArgs = commonArgs // {
|
||||
pname = "trunk-workspace-wasm";
|
||||
cargoExtraArgs = "--package=client";
|
||||
};
|
||||
|
||||
cargoArtifactsWasm = craneLib.buildDepsOnly (wasmArgs // {
|
||||
doCheck = false;
|
||||
});
|
||||
|
||||
# Build the frontend of the application.
|
||||
# This derivation is a directory you can put on a webserver.
|
||||
myClient = craneLib.buildTrunkPackage (wasmArgs // {
|
||||
pname = "trunk-workspace-client";
|
||||
cargoArtifacts = cargoArtifactsWasm;
|
||||
trunkIndexPath = "client/index.html";
|
||||
});
|
||||
in
|
||||
{
|
||||
checks = {
|
||||
# Build the crate as part of `nix flake check` for convenience
|
||||
inherit myServer myClient;
|
||||
|
||||
# Run clippy (and deny all warnings) on the crate source,
|
||||
# again, reusing the dependency artifacts from above.
|
||||
#
|
||||
# Note that this is done as a separate derivation so that
|
||||
# we can block the CI if there are issues here, but not
|
||||
# prevent downstream consumers from building our crate by itself.
|
||||
my-app-clippy = craneLib.cargoClippy (commonArgs // {
|
||||
inherit cargoArtifacts;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
# Here we don't care about serving the frontend
|
||||
CLIENT_DIST = "";
|
||||
});
|
||||
|
||||
# Check formatting
|
||||
my-app-fmt = craneLib.cargoFmt commonArgs;
|
||||
};
|
||||
|
||||
apps.default = flake-utils.lib.mkApp {
|
||||
name = "server";
|
||||
drv = myServer;
|
||||
};
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
inputsFrom = builtins.attrValues self.checks;
|
||||
|
||||
shellHook = ''
|
||||
export CLIENT_DIST=$PWD/client/dist;
|
||||
'';
|
||||
|
||||
# Extra inputs can be added here
|
||||
nativeBuildInputs = with pkgs; [
|
||||
cargo
|
||||
rustc
|
||||
trunk
|
||||
];
|
||||
};
|
||||
});
|
||||
}
|
12
examples/trunk-workspace/server/Cargo.toml
Normal file
12
examples/trunk-workspace/server/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "server"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
axum = "0.6.16"
|
||||
shared = { version = "0.1.0", path = "../shared" }
|
||||
tokio = { version = "1.27.0", features = ["full"] }
|
||||
tower-http = { version = "0.4.0", features = ["full"] }
|
34
examples/trunk-workspace/server/src/main.rs
Normal file
34
examples/trunk-workspace/server/src/main.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use axum::{routing::get, Json, Router};
|
||||
|
||||
use shared::Post;
|
||||
use tower_http::{cors::CorsLayer, services::ServeDir};
|
||||
|
||||
async fn list_posts() -> Json<Vec<Post>> {
|
||||
Json(vec![
|
||||
Post {
|
||||
title: "How to use yew???????".to_string(),
|
||||
text: "...".to_string(),
|
||||
author_name: "Jane Doe".to_string(),
|
||||
},
|
||||
Post {
|
||||
title: "How to use axum???????".to_string(),
|
||||
text: "...".to_string(),
|
||||
author_name: "Jonh Doe".to_string(),
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let app = Router::new()
|
||||
.nest_service("/", ServeDir::new(env!("CLIENT_DIST")))
|
||||
.route("/posts", get(list_posts))
|
||||
.layer(CorsLayer::permissive());
|
||||
|
||||
let addr = "0.0.0.0:8000";
|
||||
eprintln!("Listening on {addr}");
|
||||
axum::Server::bind(&addr.parse().unwrap())
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
9
examples/trunk-workspace/shared/Cargo.toml
Normal file
9
examples/trunk-workspace/shared/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "shared"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
8
examples/trunk-workspace/shared/src/lib.rs
Normal file
8
examples/trunk-workspace/shared/src/lib.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Post {
|
||||
pub title: String,
|
||||
pub text: String,
|
||||
pub author_name: String,
|
||||
}
|
879
examples/trunk/Cargo.lock
generated
Normal file
879
examples/trunk/Cargo.lock
generated
Normal file
@ -0,0 +1,879 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anymap2"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d301b3b94cb4b2f23d7917810addbbaff90738e0ca2be692bd027e70d7e0330c"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "boolinator"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfa8873f51c92e232f9bac4065cddef41b714152812bfc5f7672ba16d6ef8cd9"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "console_error_panic_hook"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8"
|
||||
dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-macro",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"memchr",
|
||||
"pin-project-lite",
|
||||
"pin-utils",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a4bef6b277b3ab073253d4bca60761240cf8d6998f4bd142211957b69a61b20"
|
||||
dependencies = [
|
||||
"gloo-console",
|
||||
"gloo-dialogs",
|
||||
"gloo-events",
|
||||
"gloo-file",
|
||||
"gloo-history",
|
||||
"gloo-net",
|
||||
"gloo-render",
|
||||
"gloo-storage",
|
||||
"gloo-timers",
|
||||
"gloo-utils",
|
||||
"gloo-worker",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-console"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "82b7ce3c05debe147233596904981848862b068862e9ec3e34be446077190d3f"
|
||||
dependencies = [
|
||||
"gloo-utils",
|
||||
"js-sys",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-dialogs"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67062364ac72d27f08445a46cab428188e2e224ec9e37efdba48ae8c289002e6"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-events"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68b107f8abed8105e4182de63845afcc7b69c098b7852a813ea7462a320992fc"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-file"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8d5564e570a38b43d78bdc063374a0c3098c4f0d64005b12f9bbe87e869b6d7"
|
||||
dependencies = [
|
||||
"gloo-events",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-history"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd451019e0b7a2b8a7a7b23e74916601abf1135c54664e57ff71dcc26dfcdeb7"
|
||||
dependencies = [
|
||||
"gloo-events",
|
||||
"gloo-utils",
|
||||
"serde",
|
||||
"serde-wasm-bindgen",
|
||||
"serde_urlencoded",
|
||||
"thiserror",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-net"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9902a044653b26b99f7e3693a42f171312d9be8b26b5697bd1e43ad1f8a35e10"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"gloo-utils",
|
||||
"js-sys",
|
||||
"pin-project",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-render"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fd9306aef67cfd4449823aadcd14e3958e0800aa2183955a309112a84ec7764"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-storage"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d6ab60bf5dbfd6f0ed1f7843da31b41010515c745735c970e821945ca91e480"
|
||||
dependencies = [
|
||||
"gloo-utils",
|
||||
"js-sys",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-timers"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-utils"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8e8fc851e9c7b9852508bc6e3f690f452f474417e8545ec9857b7f7377036b5"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-worker"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13471584da78061a28306d1359dd0178d8d6fc1c7c80e5e35d27260346e0516a"
|
||||
dependencies = [
|
||||
"anymap2",
|
||||
"bincode",
|
||||
"gloo-console",
|
||||
"gloo-utils",
|
||||
"js-sys",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "implicit-clone"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40fc102e70475c320b185cd18c1e48bba2d7210b63970a4d581ef903e4368ef7"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.141"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc"
|
||||
dependencies = [
|
||||
"pin-project-internal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-internal"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "pinned"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a829027bd95e54cfe13e3e258a1ae7b645960553fb82b75ff852c29688ee595b"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"rustversion",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.1.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.56"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prokio"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03b55e106e5791fa5a13abd13c85d6127312e8e09098059ca2bc9b03ca4cf488"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"gloo",
|
||||
"num_cpus",
|
||||
"once_cell",
|
||||
"pin-project",
|
||||
"pinned",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"wasm-bindgen-futures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-start"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"yew",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.160"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde-wasm-bindgen"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.160"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.96"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.27.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"pin-project-lite",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-stream"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.4.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.45.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
|
||||
|
||||
[[package]]
|
||||
name = "yew"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dbecfe44343b70cc2932c3eb445425969ae21754a8ab3a0966981c1cf7af1cc"
|
||||
dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"futures",
|
||||
"gloo",
|
||||
"implicit-clone",
|
||||
"indexmap",
|
||||
"js-sys",
|
||||
"prokio",
|
||||
"rustversion",
|
||||
"serde",
|
||||
"slab",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"yew-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yew-macro"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b64c253c1d401f1ea868ca9988db63958cfa15a69f739101f338d6f05eea8301"
|
||||
dependencies = [
|
||||
"boolinator",
|
||||
"once_cell",
|
||||
"prettyplease",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
9
examples/trunk/Cargo.toml
Normal file
9
examples/trunk/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "trunk-simple"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
yew = { version = "0.20", features = ["csr"] }
|
119
examples/trunk/flake.nix
Normal file
119
examples/trunk/flake.nix
Normal file
@ -0,0 +1,119 @@
|
||||
{
|
||||
description = "Build a cargo project";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
|
||||
crane = {
|
||||
url = "github:ipetkov/crane";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs = {
|
||||
nixpkgs.follows = "nixpkgs";
|
||||
flake-utils.follows = "flake-utils";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ (import rust-overlay) ];
|
||||
};
|
||||
|
||||
inherit (pkgs) lib;
|
||||
|
||||
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||
# Set the build targets supported by the toolchain,
|
||||
# wasm32-unknown-unknown is required for trunk
|
||||
targets = [ "wasm32-unknown-unknown" ];
|
||||
};
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
||||
|
||||
# When filtering sources, we want to allow assets other than .rs files
|
||||
src = lib.cleanSourceWith {
|
||||
src = ./.; # The original, unfiltered source
|
||||
filter = path: type:
|
||||
(lib.hasSuffix "\.html" path) ||
|
||||
(lib.hasSuffix "\.scss" path) ||
|
||||
# Example of a folder for images, icons, etc
|
||||
(lib.hasInfix "/assets/" path) ||
|
||||
# Default filter from crane (allow .rs files)
|
||||
(craneLib.filterCargoSources path type)
|
||||
;
|
||||
};
|
||||
|
||||
# Common arguments can be set here to avoid repeating them later
|
||||
commonArgs = {
|
||||
inherit src;
|
||||
# We must force the target, otherwise cargo will attempt to use your native target
|
||||
cargoExtraArgs = "--target=wasm32-unknown-unknown";
|
||||
};
|
||||
|
||||
# Build *just* the cargo dependencies, so we can reuse
|
||||
# all of that work (e.g. via cachix) when running in CI
|
||||
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
|
||||
# You cannot run cargo test on a wasm build
|
||||
doCheck = false;
|
||||
});
|
||||
|
||||
# Build the actual crate itself, reusing the dependency
|
||||
# artifacts from above.
|
||||
# This derivation is a directory you can put on a webserver.
|
||||
my-app = craneLib.buildTrunkPackage (commonArgs // {
|
||||
inherit cargoArtifacts;
|
||||
});
|
||||
|
||||
# Quick example on how to serve the app,
|
||||
# This is just an example, not useful for production environments
|
||||
serve-app = pkgs.writeShellScriptBin "serve-app" ''
|
||||
${pkgs.python3Minimal}/bin/python3 -m http.server --directory ${my-app} 8000
|
||||
'';
|
||||
in
|
||||
{
|
||||
checks = {
|
||||
# Build the crate as part of `nix flake check` for convenience
|
||||
inherit my-app;
|
||||
|
||||
# Run clippy (and deny all warnings) on the crate source,
|
||||
# again, reusing the dependency artifacts from above.
|
||||
#
|
||||
# Note that this is done as a separate derivation so that
|
||||
# we can block the CI if there are issues here, but not
|
||||
# prevent downstream consumers from building our crate by itself.
|
||||
my-app-clippy = craneLib.cargoClippy (commonArgs // {
|
||||
inherit cargoArtifacts;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
});
|
||||
|
||||
# Check formatting
|
||||
my-app-fmt = craneLib.cargoFmt {
|
||||
inherit src;
|
||||
};
|
||||
};
|
||||
|
||||
packages.default = my-app;
|
||||
|
||||
apps.default = flake-utils.lib.mkApp {
|
||||
drv = serve-app;
|
||||
};
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
inputsFrom = builtins.attrValues self.checks;
|
||||
|
||||
# Extra inputs can be added here
|
||||
nativeBuildInputs = with pkgs; [
|
||||
cargo
|
||||
rustc
|
||||
trunk
|
||||
];
|
||||
};
|
||||
});
|
||||
}
|
7
examples/trunk/index.html
Normal file
7
examples/trunk/index.html
Normal file
@ -0,0 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Trunk App</title>
|
||||
</head>
|
||||
</html>
|
14
examples/trunk/src/main.rs
Normal file
14
examples/trunk/src/main.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use yew::prelude::*;
|
||||
|
||||
#[function_component]
|
||||
fn App() -> Html {
|
||||
html! {
|
||||
<h1>
|
||||
{"Hello world!"}
|
||||
</h1>
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
yew::Renderer::<App>::new().render();
|
||||
}
|
10
flake.nix
10
flake.nix
@ -65,6 +65,16 @@
|
||||
description = "Build a cargo project without extra checks";
|
||||
path = ./examples/quick-start-simple;
|
||||
};
|
||||
|
||||
trunk = {
|
||||
description = "Build a trunk project";
|
||||
path = ./examples/trunk;
|
||||
};
|
||||
|
||||
trunk-workspace = {
|
||||
description = "Build a workspace with a trunk member";
|
||||
path = ./examples/trunk-workspace;
|
||||
};
|
||||
};
|
||||
} // flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
|
77
lib/buildTrunkPackage.nix
Normal file
77
lib/buildTrunkPackage.nix
Normal file
@ -0,0 +1,77 @@
|
||||
{ binaryen
|
||||
, buildDepsOnly
|
||||
, crateNameFromCargoToml
|
||||
, mkCargoDerivation
|
||||
, nodePackages
|
||||
, trunk
|
||||
, vendorCargoDeps
|
||||
, wasm-bindgen-cli
|
||||
}:
|
||||
|
||||
{ trunkExtraArgs ? ""
|
||||
, trunkExtraBuildArgs ? ""
|
||||
, trunkIndexPath ? "./index.html"
|
||||
, ...
|
||||
}@origArgs:
|
||||
let
|
||||
cleanedArgs = builtins.removeAttrs origArgs [
|
||||
"installPhase"
|
||||
"installPhaseCommand"
|
||||
"trunkExtraArgs"
|
||||
"trunkExtraBuildArgs"
|
||||
"trunkIndexPath"
|
||||
];
|
||||
|
||||
crateName = crateNameFromCargoToml cleanedArgs;
|
||||
|
||||
# Avoid recomputing values when passing args down
|
||||
args = cleanedArgs // {
|
||||
pname = cleanedArgs.pname or crateName.pname;
|
||||
version = cleanedArgs.version or crateName.version;
|
||||
cargoVendorDir = cleanedArgs.cargoVendorDir or (vendorCargoDeps cleanedArgs);
|
||||
};
|
||||
in
|
||||
mkCargoDerivation (args // {
|
||||
pnameSuffix = "-trunk";
|
||||
|
||||
cargoArtifacts = args.cargoArtifacts or (buildDepsOnly (args // {
|
||||
CARGO_BUILD_TARGET = args.CARGO_BUILD_TARGET or "wasm32-unknown-unknown";
|
||||
installCargoArtifactsMode = args.installCargoArtifactsMode or "use-zstd";
|
||||
doCheck = args.doCheck or false;
|
||||
}));
|
||||
|
||||
# Force trunk to not download dependencies, but set the version with
|
||||
# whatever tools actually make it into the builder's PATH
|
||||
preConfigure = ''
|
||||
echo configuring trunk tools
|
||||
export TRUNK_TOOLS_SASS=$(sass --version | cut -d' ' -f1)
|
||||
export TRUNK_TOOLS_WASM_BINDGEN=$(wasm-bindgen --version | cut -d' ' -f2)
|
||||
export TRUNK_TOOLS_WASM_OPT=$(wasm-opt --version | cut -d' ' -f3)
|
||||
|
||||
echo "TRUNK_TOOLS_SASS=''${TRUNK_TOOLS_SASS}"
|
||||
echo "TRUNK_TOOLS_WASM_BINDGEN=''${TRUNK_TOOLS_WASM_BINDGEN}"
|
||||
echo "TRUNK_TOOLS_WASM_OPT=''${TRUNK_TOOLS_WASM_OPT}"
|
||||
'';
|
||||
|
||||
buildPhaseCargoCommand = args.buildPhaseCommand or ''
|
||||
local profileArgs=""
|
||||
if [[ "$CARGO_PROFILE" == "release" ]]; then
|
||||
profileArgs="--release"
|
||||
fi
|
||||
|
||||
trunk ${trunkExtraArgs} build $profileArgs ${trunkExtraBuildArgs} "${trunkIndexPath}"
|
||||
'';
|
||||
|
||||
installPhase = args.installPhase or ''
|
||||
cp -r "$(dirname "${trunkIndexPath}")/dist" $out
|
||||
'';
|
||||
|
||||
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
|
||||
binaryen
|
||||
# dart-sass compiled to javascript
|
||||
# TODO: replace with a native version when it comes to nixpkgs
|
||||
nodePackages.sass
|
||||
trunk
|
||||
wasm-bindgen-cli
|
||||
];
|
||||
})
|
@ -15,6 +15,7 @@ in
|
||||
|
||||
buildDepsOnly = callPackage ./buildDepsOnly.nix { };
|
||||
buildPackage = callPackage ./buildPackage.nix { };
|
||||
buildTrunkPackage = callPackage ./buildTrunkPackage.nix { };
|
||||
cargoAudit = callPackage ./cargoAudit.nix { };
|
||||
cargoBuild = callPackage ./cargoBuild.nix { };
|
||||
cargoClippy = callPackage ./cargoClippy.nix { };
|
||||
|
Loading…
Reference in New Issue
Block a user