Skip to content

Commit

Permalink
re-export async-nats, bump async-nats to 0.27.1 (#135)
Browse files Browse the repository at this point in the history
* re-export async-nats, bump async-nats to 0.25.1

Signed-off-by: stevelr <[email protected]>

* re-export async-nats. bump to 0.11.3

Signed-off-by: stevelr <[email protected]>

* make Transport Send + Sync

Signed-off-by: stevelr <[email protected]>

* add Clone to _Sender

Signed-off-by: stevelr <[email protected]>

* bump codegen

Signed-off-by: stevelr <[email protected]>

* smithy-bindgen macros

Signed-off-by: stevelr <[email protected]>

* docs

Signed-off-by: stevelr <[email protected]>

* add some tests

Signed-off-by: stevelr <[email protected]>

* add gh workflow file, rustfmt

Signed-off-by: stevelr <[email protected]>

* bump weld-codegen to 0.6.1

Signed-off-by: stevelr <[email protected]>

* undo bump version

Signed-off-by: stevelr <[email protected]>

* remove scratch file

Signed-off-by: stevelr <[email protected]>

* README update

Signed-off-by: stevelr <[email protected]>

* remove unused symbols

Signed-off-by: stevelr <[email protected]>

* improve docs

Signed-off-by: stevelr <[email protected]>

* more docs

Signed-off-by: stevelr <[email protected]>

* make Transport Send + Sync so a Sender can be run in a spawned task

Signed-off-by: stevelr <[email protected]>

* bump async-nats to 0.27.1

Signed-off-by: stevelr <[email protected]>

* fix Transport Clone

Signed-off-by: stevelr <[email protected]>

* add test case for keyvalue struct

Signed-off-by: stevelr <[email protected]>

* update crates: wasmbus-rpc to 0.12.0, weld-codegen to 0.7.0

Signed-off-by: stevelr <[email protected]>

* make Transport Clone, fix clippy errors

Signed-off-by: stevelr <[email protected]>

---------

Signed-off-by: stevelr <[email protected]>
  • Loading branch information
stevelr authored Feb 28, 2023
1 parent 619b2f9 commit 7491084
Show file tree
Hide file tree
Showing 30 changed files with 789 additions and 152 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/smithy-bindgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: SMITHY_BINDGEN

on:
push:
branches: [main]
paths:
- "smithy-bindgen/**"
tags:
- "smithy-bindgen-v*"
pull_request:
branches: [main]
paths:
- "smithy-bindgen/**"

env:
CARGO_TERM_COLOR: always
working-directory: ./smithy-bindgen

jobs:
rust_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Update rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: run_all_tests_clippy_fmt
working-directory: ${{ env.working-directory }}
run: |
make test
make rust-check
github_release:
if: startswith(github.ref, 'refs/tags/') # Only run on tag push
needs: rust_test
runs-on: ubuntu-latest
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: true

crates_release:
if: startswith(github.ref, 'refs/tags/') # Only run on tag push
needs: github_release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- id: crates-release-action
uses: wasmcloud/common-actions/crates-release@main
with:
working-directory: ${{ env.working-directory }}
crates-token: ${{ secrets.CRATES_PUBLISH_TOKEN }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# If you're on mac, `brew install make`
# and ensure `/usr/local/opt/make/libexec/gnubin` is in your PATH before /usr/bin

subdirs = codegen macros rpc-rs
subdirs = codegen macros smithy-bindgen rpc-rs

all build release clean test update lint validate rust-check::
for dir in $(subdirs); do \
Expand Down
4 changes: 2 additions & 2 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "weld-codegen"
version = "0.6.0"
version = "0.7.0"
edition = "2021"
authors = [ "wasmcloud Team" ]
license = "Apache-2.0"
Expand Down Expand Up @@ -40,7 +40,7 @@ serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tempfile = "3.2"
thiserror = "1.0"
toml = "0.5"
toml = "0.7"

[lib]
name = "weld_codegen"
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/codegen_go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl<'model> CodeGen for GoCodeGen<'model> {
&mut self,
model: Option<&Model>,
_lc: &LanguageConfig,
_output_dir: &Path,
_output_dir: Option<&Path>,
_renderer: &mut Renderer,
) -> std::result::Result<(), Error> {
self.namespace = None;
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/codegen_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'model> CodeGen for PythonCodeGen<'model> {
&mut self,
model: Option<&Model>,
_lc: &LanguageConfig,
_output_dir: &Path,
_output_dir: Option<&Path>,
_renderer: &mut Renderer,
) -> std::result::Result<(), Error> {
self.namespace = None;
Expand Down
4 changes: 2 additions & 2 deletions codegen/src/codegen_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl<'model> CodeGen for RustCodeGen<'model> {
&mut self,
model: Option<&Model>,
_lc: &LanguageConfig,
_output_dir: &Path,
_output_dir: Option<&Path>,
_renderer: &mut Renderer,
) -> std::result::Result<(), Error> {
self.namespace = None;
Expand Down Expand Up @@ -1212,7 +1212,7 @@ impl<'model> RustCodeGen<'model> {
writeln!(
w,
r#"/// client for sending {} messages
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct {}Sender<T:Transport> {{ transport: T }}
impl<T:Transport> {}Sender<T> {{
Expand Down
17 changes: 7 additions & 10 deletions codegen/src/docgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
format::SourceFormatter,
gen::{to_json, CodeGen},
render::Renderer,
writer::Writer,
Bytes, Error, JsonValue, ParamMap,
};

Expand Down Expand Up @@ -42,9 +43,13 @@ impl CodeGen for DocGen {
&mut self,
model: Option<&Model>,
lc: &LanguageConfig,
output_dir: &Path,
output_dir: Option<&Path>,
renderer: &mut Renderer,
) -> std::result::Result<(), Error> {
let output_dir = match output_dir {
None => return Ok(()),
Some(d) => d,
};
let model = match model {
None => return Ok(()),
Some(model) => model,
Expand Down Expand Up @@ -75,18 +80,9 @@ impl CodeGen for DocGen {
.map(|id| id.to_string())
.collect::<BTreeSet<String>>();

std::fs::create_dir_all(output_dir).map_err(|e| {
Error::Io(format!(
"creating directory {}: {}",
output_dir.display(),
e
))
})?;

for ns in namespaces.iter() {
let output_file =
output_dir.join(format!("{}.html", crate::strings::to_snake_case(ns)));

let mut out = std::fs::File::create(&output_file).map_err(|e| {
Error::Io(format!(
"writing output file {}: {}",
Expand All @@ -105,6 +101,7 @@ impl CodeGen for DocGen {
/// DocGen doesn't do per-file generation so this is a no-op
fn generate_file(
&mut self,
_w: &mut Writer,
_model: &Model,
_file_config: &OutputFile,
_params: &ParamMap,
Expand Down
44 changes: 18 additions & 26 deletions codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ impl<'model> Generator {
for (name, template) in COMMON_TEMPLATES.iter() {
renderer.add_template((name, template))?;
}
std::fs::create_dir_all(&output_dir).map_err(|e| {
Error::Io(format!(
"creating directory {}: {}",
&output_dir.display(),
e
))
})?;

for (language, mut lc) in config.languages.into_iter() {
if !config.output_languages.is_empty() && !config.output_languages.contains(&language) {
Expand All @@ -117,27 +110,26 @@ impl<'model> Generator {
}
// if language output_dir is relative, append it, otherwise use it
let output_dir = if lc.output_dir.is_absolute() {
std::fs::create_dir_all(&lc.output_dir).map_err(|e| {
Error::Io(format!(
"creating directory {}: {}",
&lc.output_dir.display(),
e
))
})?;
lc.output_dir.clone()
} else {
output_dir.join(&lc.output_dir)
};
std::fs::create_dir_all(&output_dir).map_err(|e| {
Error::Io(format!(
"creating directory {}: {}",
output_dir.display(),
e
))
})?;
// add command-line overrides
for (k, v) in defines.iter() {
lc.parameters.insert(k.to_string(), v.clone());
}
let base_params: BTreeMap<String, JsonValue> = to_json(&lc.parameters)?;

let mut cgen = gen_for_language(&language, model);

// initialize generator
cgen.init(model, &lc, &output_dir, &mut renderer)?;
cgen.init(model, &lc, Some(&output_dir), &mut renderer)?;

// A common param dictionary is shared (read-only) by the renderer and the code generator,
// Parameters include the following:
Expand Down Expand Up @@ -200,7 +192,8 @@ impl<'model> Generator {
))
})?;
} else if let Some(model) = model {
let bytes = cgen.generate_file(model, file_config, &params)?;
let mut w: Writer = Writer::default();
let bytes = cgen.generate_file(&mut w, model, file_config, &params)?;
std::fs::write(&out_path, &bytes).map_err(|e| {
Error::Io(format!("writing output file {}: {}", out_path.display(), e))
})?;
Expand Down Expand Up @@ -243,7 +236,7 @@ fn gen_for_language<'model>(
/// - write_services()
/// - finalize()
///
pub(crate) trait CodeGen {
pub trait CodeGen {
/// Initialize code generator and renderer for language output.j
/// This hook is called before any code is generated and can be used to initialize code generator
/// and/or perform additional processing before output files are created.
Expand All @@ -252,7 +245,7 @@ pub(crate) trait CodeGen {
&mut self,
model: Option<&Model>,
lc: &LanguageConfig,
output_dir: &Path,
output_dir: Option<&Path>,
renderer: &mut Renderer,
) -> std::result::Result<(), Error> {
Ok(())
Expand All @@ -263,17 +256,16 @@ pub(crate) trait CodeGen {
/// The return value is Bytes containing the data that should be written to the output file.
fn generate_file(
&mut self,
w: &mut Writer,
model: &Model,
file_config: &OutputFile,
params: &ParamMap,
) -> Result<Bytes> {
let mut w: Writer = Writer::default();

self.init_file(&mut w, model, file_config, params)?;
self.write_source_file_header(&mut w, model, params)?;
self.declare_types(&mut w, model, params)?;
self.write_services(&mut w, model, params)?;
self.finalize(&mut w)
self.init_file(w, model, file_config, params)?;
self.write_source_file_header(w, model, params)?;
self.declare_types(w, model, params)?;
self.write_services(w, model, params)?;
self.finalize(w)
}

/// Perform any initialization required prior to code generation for a file
Expand Down
7 changes: 7 additions & 0 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ pub(crate) mod wasmbus_model {
include!("./wasmbus_model.rs");
}

// enable other tools to invoke codegen directly. Add other languages as needed
pub mod generators {
pub use crate::codegen_go::GoCodeGen;
pub use crate::codegen_rust::RustCodeGen;
pub use crate::gen::CodeGen;
}

// re-export
pub use bytes::Bytes;
pub(crate) use bytes::BytesMut;
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ pub fn has_default(model: &'_ Model, member: &MemberShape) -> bool {
}
}

pub(crate) struct NumberedMember {
pub struct NumberedMember {
field_num: Option<u16>,
shape: MemberShape,
}
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/wasmbus_model.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is @generated by wasmcloud/weld-codegen 0.5.0.
// This file is @generated by wasmcloud/weld-codegen 0.7.0.
// It is not intended for manual editing.
// namespace: org.wasmcloud.model

Expand Down
6 changes: 3 additions & 3 deletions rpc-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasmbus-rpc"
version = "0.11.2"
version = "0.12.0"
authors = [ "wasmcloud Team" ]
license = "Apache-2.0"
description = "Runtime library for actors and capability providers"
Expand Down Expand Up @@ -46,7 +46,7 @@ num-bigint = { version = "0.4", optional = true }
bigdecimal = { version = "0.3", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
async-nats = "0.23.0"
async-nats = "0.27.1"
atty = "0.2"
data-encoding = "2.3"
futures = "0.3"
Expand All @@ -70,4 +70,4 @@ clap = { version = "4.0.22", features = ["derive"] }
test-log = { version = "0.2.10", default-features = false, features = ["trace"] }

[build-dependencies]
weld-codegen = { version = "0.6.0", path = "../codegen" }
weld-codegen = { version = "0.7.0", path = "../codegen" }
4 changes: 2 additions & 2 deletions rpc-rs/examples/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use nkeys::KeyPairType;
use std::path::PathBuf;
use std::sync::Arc;
use wascap::prelude::KeyPair;
use wasmbus_rpc::rpc_client::RpcClient;
use wasmbus_rpc::{async_nats::connect, rpc_client::RpcClient};

/// RpcClient test CLI for making nats request
#[derive(Parser)]
Expand Down Expand Up @@ -54,7 +54,7 @@ async fn main() -> Result<()> {
let timeout = args.timeout_ms.map(|n| std::time::Duration::from_millis(n as u64));
let kp = Arc::new(KeyPair::new(KeyPairType::User));
let nats_uri = args.nats.unwrap_or_else(|| "nats://127.0.0.1:4222".to_string());
let nc = async_nats::connect(&nats_uri).await?;
let nc = connect(&nats_uri).await?;
let client = RpcClient::new(nc, "HOST".into(), timeout, kp);

let resp = client.request(args.subject, data).await?;
Expand Down
4 changes: 2 additions & 2 deletions rpc-rs/examples/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use futures::StreamExt;
use nkeys::KeyPairType;
use std::sync::Arc;
use wascap::prelude::KeyPair;
use wasmbus_rpc::rpc_client::RpcClient;
use wasmbus_rpc::{async_nats::connect, rpc_client::RpcClient};

/// RpcClient test CLI for connection and subscription
#[derive(Parser)]
Expand All @@ -27,7 +27,7 @@ async fn main() -> Result<()> {
}
let kp = Arc::new(KeyPair::new(KeyPairType::User));
let nats_uri = args.nats.unwrap_or_else(|| "nats://127.0.0.1:4222".to_string());
let nc = async_nats::connect(&nats_uri).await?;
let nc = connect(&nats_uri).await?;
let client = RpcClient::new(nc, "HOST".into(), None, kp);

println!("Subscribing to {}", &args.subject);
Expand Down
4 changes: 2 additions & 2 deletions rpc-rs/src/chunkify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::{
sync::{Arc, RwLock},
};

use async_nats::jetstream::{
use crate::async_nats::jetstream::{
self,
object_store::{Config, ObjectStore},
Context,
Expand Down Expand Up @@ -73,7 +73,7 @@ impl ChunkEndpoint {

pub(crate) fn with_client(
lattice: String,
nc: async_nats::Client,
nc: crate::async_nats::Client,
domain: Option<String>,
) -> Self {
let map = jetstream_map();
Expand Down
4 changes: 2 additions & 2 deletions rpc-rs/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl SendOpts {
/// Transport determines how messages are sent
/// Alternate implementations could be mock-server, or test-fuzz-server / test-fuzz-client
#[async_trait]
pub trait Transport: Send {
pub trait Transport: Send + Sync + Clone {
async fn send(
&self,
ctx: &Context,
Expand Down Expand Up @@ -221,7 +221,7 @@ impl<T: Transport> AnySender<T> {
}
}

impl<T: Transport + Sync + Send> AnySender<T> {
impl<T: Transport> AnySender<T> {
/// Send encoded payload
#[inline]
async fn send_raw<'s, 'ctx, 'msg>(
Expand Down
Loading

0 comments on commit 7491084

Please sign in to comment.