Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(backend)!: separate tower and warp #65

Merged
merged 16 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: davidB/rust-cargo-make@v1

- name: Run Lints
run: ci/feature-soundness.sh
run: cargo make clippy

rustfmt:
name: Check Formatting
Expand Down Expand Up @@ -68,21 +68,39 @@ jobs:
with:
tool: cargo-generate

- name: Install cargo-make
uses: davidB/rust-cargo-make@v1

- name: Set Stellation Target to 'ci'
run: |
echo 'variable::set("stellation_target", "ci");' >> stellation/templates/default/resolve-crates.rhai

- name: Generate Template
run: |
cargo generate --path stellation/templates/default \
--name template-default-generated
set -x
mkdir templates-generated/
cd templates-generated

for x in $(ls ../stellation/templates); do
if [ -d ../stellation/templates/$x ];
then
echo "Creating Template $x..."
cargo generate --path ../stellation/templates/$x \
--name generated-$x
fi
done

- name: Run Lints
run: |
cargo clippy --bin stctl
cargo clippy --bin template-default-generated-client
cargo clippy --bin template-default-generated-server
working-directory: template-default-generated
set -x

for x in $(ls); do
cd $x
cargo make clippy
cd ..
done

working-directory: templates-generated

publish:
name: Publish to crates.io
Expand All @@ -109,6 +127,9 @@ jobs:
- name: Configure sccache
uses: visvirial/sccache-action@v1.0.1

- name: Install cargo-make
uses: davidB/rust-cargo-make@v1

- name: Set Git Information
run: |
git config --global user.name "Stellation Actions"
Expand Down Expand Up @@ -141,23 +162,29 @@ jobs:
run: |
echo "CARGO_PUBLISH_EXTRA_ARGS=--token=${{ secrets.CRATES_IO_TOKEN }}" >> $GITHUB_ENV

# Run lints first so it will be faster to run publish checks.
- name: Run Lints
run: cargo make clippy

- name: Run cargo publish
run: |
CRATES=(
stellation-core
stellation-bridge
stellation-backend
stellation-backend-warp
stellation-backend-tower
stellation-backend-cli
stellation-frontend
stctl
stellation
)

for CRATE_NAME in "${CRATES[@]}";
for s in "${CRATES[@]}";
do
cargo publish \
${{ env.CARGO_PUBLISH_EXTRA_ARGS }} \
--manifest-path crates/$CRATE_NAME/Cargo.toml
--manifest-path crates/$s/Cargo.toml
done

env:
Expand Down
54 changes: 41 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,19 @@ workspace = false
command = "cargo"
args = ["run", "--bin", "stctl", "--", "${@}"]

[config]
log_level = "info"
[tasks.clippy]
clear = true
workspace = false
script = '''
#!/usr/bin/env bash
set -e

cargo clippy --workspace --all-features -- -D warnings

# We should lint bridge separately as resolvable features result in different behaviours.
cargo clippy -p stellation-bridge -- -D warnings
cargo clippy -p stellation-bridge --features=resolvable -- -D warnings

cargo clippy -p example-fullstack-client -- -D warnings
cargo clippy -p example-fullstack-server -- -D warnings
'''
24 changes: 0 additions & 24 deletions ci/feature-soundness.sh

This file was deleted.

2 changes: 1 addition & 1 deletion ci/switch-registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def main() -> None:
print(f"Updating {cargo_toml_path}...")

for (key, value) in cfg["dependencies"].items():
if key != "stctl" and not key.startswith("stellation-"):
if not isinstance(value, dict) or "path" not in value.keys():
print(f" Skipping {key}...")
continue

Expand Down
36 changes: 36 additions & 0 deletions ci/update-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3

import tomlkit
import glob
import sys
from pathlib import Path

def main() -> None:
cwd = Path.cwd()
next_ver = sys.argv[1]

if next_ver.startswith('v'):
next_ver = next_ver[1:]

print(f"Running in {cwd}...")

for cargo_toml_path in cwd.glob("crates/*/Cargo.toml"):
cfg = tomlkit.loads(cargo_toml_path.open().read())
print(f"Updating {cargo_toml_path} to version {next_ver}...")

cfg["package"]["version"] = next_ver

for (key, value) in cfg["dependencies"].items():
if not isinstance(value, dict) or "path" not in value.keys():
print(f" Skipping {key}...")
continue

print(f" Updating {key} to version {next_ver}...")
value["version"] = next_ver

with cargo_toml_path.open("w") as f:
f.write(tomlkit.dumps(cfg))
f.flush()

if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion crates/stellation-backend-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ license = "MIT OR Apache-2.0"

[dependencies]
# Stellation Components
stellation-backend = { version = "0.1.4", path = "../stellation-backend", features = ["hyper-server"] }
stellation-backend = { version = "0.1.4", path = "../stellation-backend" }
stellation-backend-tower = { version = "0.1.4", path = "../stellation-backend-tower" }
stellation-core = { version = "0.1.4", path = "../stellation-core" }

# Yew / Component Related
Expand Down
12 changes: 7 additions & 5 deletions crates/stellation-backend-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use std::path::PathBuf;

use anyhow::{anyhow, Context};
use clap::Parser;
use stellation_backend::{Endpoint, Frontend, Server, ServerAppProps};
use stellation_backend::ServerAppProps;
use stellation_backend_tower::{Frontend, Server, TowerEndpoint, TowerRequest};
use stellation_core::dev::StctlMetadata;
use typed_builder::TypedBuilder;
use yew::BaseComponent;
Expand All @@ -21,17 +22,18 @@ struct Arguments {

/// The default command line instance for the backend server.
#[derive(Debug, TypedBuilder)]
pub struct Cli<COMP, CTX = ()>
pub struct Cli<COMP, CTX = (), BCTX = ()>
where
COMP: BaseComponent,
{
endpoint: Endpoint<COMP, CTX>,
endpoint: TowerEndpoint<COMP, CTX, BCTX>,
}

impl<COMP, CTX> Cli<COMP, CTX>
impl<COMP, CTX, BCTX> Cli<COMP, CTX, BCTX>
where
COMP: BaseComponent<Properties = ServerAppProps<CTX>>,
COMP: BaseComponent<Properties = ServerAppProps<CTX, TowerRequest<CTX>>>,
CTX: 'static,
BCTX: 'static,
{
/// Parses the arguments and runs the server.
pub async fn run(self) -> anyhow::Result<()> {
Expand Down
32 changes: 32 additions & 0 deletions crates/stellation-backend-tower/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "stellation-backend-tower"
version = "0.1.4"
edition = "2021"
rust-version = "1.66"
repository = "https://github.com/futursolo/stellation"
authors = [
"Kaede Hoshiakwa <futursolo@icloud.com>",
]
description = "The framework experience for Yew."
keywords = ["web", "wasm", "yew", "framework", "ssr"]
categories = ["wasm", "web-programming"]
readme = "../../README.md"
homepage = "https://github.com/futursolo/stellation"
license = "MIT OR Apache-2.0"

[dependencies]
hyper = { version = "0.14.23", features = ["runtime", "server", "http1"] }
tower = { version = "0.4", features = ["util"] }
tokio = { version = "1" }
futures = { version = "0.3", default-features = false, features = ["std"] }
yew = { version = "0.20", features = ["ssr"] }
warp = { version = "0.3.3", default-features = false }

# Stellation Components
stellation-backend-warp = { version = "0.1.4", path = "../stellation-backend-warp" }
stellation-backend = { version = "0.1.4", path = "../stellation-backend" }
stellation-bridge = { version = "0.1.4", path = "../stellation-bridge", features = ["resolvable"] }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "documenting"]
Loading