Skip to content

Commit

Permalink
attempt #0
Browse files Browse the repository at this point in the history
  • Loading branch information
frantisekhanzlikbl committed Aug 21, 2022
1 parent 99bf3e6 commit df610b8
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 133 deletions.
7 changes: 7 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.1.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.1.1/direnvrc" "sha256-b6qJ4r34rbE23yWjMqbmu3ia2z4b2wIlZUksBke/ol0="
fi

use flake

source_env_if_exists .envrc.local
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Cargo.lock
*.bk
tarpc.iml
.idea

/.direnv
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nixEnvSelector.nixFile": "${workspaceRoot}/vscode-env.nix"
}
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[workspace]
resolver = "2"

members = [
"example-service",
"tarpc",
"plugins",
]
members = ["example-service", "tarpc", "plugins"]

[profile.dev]
split-debuginfo = "unpacked"
10 changes: 3 additions & 7 deletions example-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ anyhow = "1.0"
clap = { version = "3.0.0-rc.9", features = ["derive"] }
log = "0.4"
futures = "0.3"
opentelemetry = { version = "0.17", features = ["rt-tokio"] }
opentelemetry-jaeger = { version = "0.16", features = ["rt-tokio"] }
rand = "0.8"
tarpc = { version = "0.30", path = "../tarpc", features = ["full"] }
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread"] }
tarpc = { version = "0.30", path = "../tarpc", features = ["serde-transport"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1" }
tracing-opentelemetry = "0.17"
tracing-subscriber = {version = "0.3", features = ["env-filter"]}
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[lib]
name = "service"
Expand Down
6 changes: 0 additions & 6 deletions example-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ pub trait World {
pub fn init_tracing(service_name: &str) -> anyhow::Result<()> {
env::set_var("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", "12");

let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name(service_name)
.with_max_packet_size(2usize.pow(13))
.install_batch(opentelemetry::runtime::Tokio)?;

tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::from_default_env())
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::NEW | FmtSpan::CLOSE))
.with(tracing_opentelemetry::layer().with_tracer(tracer))
.try_init()?;

Ok(())
Expand Down
164 changes: 164 additions & 0 deletions flake.lock

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

45 changes: 45 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
description = "tarpc-wasm";

inputs = {
flake-compat = { url = "github:edolstra/flake-compat"; flake = false; };
nixpkgs = { url = "github:nixos/nixpkgs/nixos-unstable"; };
flake-utils = { url = "github:numtide/flake-utils"; inputs.nixpkgs.follows = "nixpkgs"; };
cargo2nix = { url = "github:cargo2nix/cargo2nix"; inputs.nixpkgs.follows = "nixpkgs"; };
rust-overlay = { url = "github:oxalica/rust-overlay"; inputs = { nixpkgs.follows = "nixpkgs"; flake-utils.follows = "flake-utils"; }; };
};

outputs = { self, nixpkgs, cargo2nix, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
cargo2nix.overlays.default
rust-overlay.overlays.default
];
};

node_pkg = pkgs.nodejs-18_x.override { enableNpm = false; };

rust = import ./nix/rust.nix {
inherit pkgs;
channel = "nightly";
version = "2022-08-16";
};
in rec {
devShell = pkgs.mkShell rec {
nativeBuildInputs = with pkgs; [
binaryen
cargo-expand
rust.toolchain
wasm-bindgen-cli
wasm-pack

node_pkg
(yarn.override { nodejs = node_pkg; }) # by default yarn uses the latest version of nodejs, so we override it to the correct version here
];
};
}
);
}
27 changes: 27 additions & 0 deletions nix/rust.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
pkgs,
channel,
version
}: let
toolchain = pkgs.rust-bin.${channel}.${version}.default.override {
extensions = [ "rust-src" "rustfmt" "rust-analyzer" ];
targets = [
(pkgs.rust.toRustTarget pkgs.stdenv.buildPlatform)
(pkgs.rust.toRustTarget pkgs.stdenv.hostPlatform)
"wasm32-unknown-unknown"
];
};

project = pkgs.rustBuilder.makePackageSet {
rustChannel = toolchain;
packageFun = import ../Cargo.nix;
target = null;
};

platform = pkgs.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};
in {
inherit toolchain project platform;
}
34 changes: 14 additions & 20 deletions tarpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name = "tarpc"
version = "0.30.0"
rust-version = "1.58.0"
authors = [
"Adam Wright <[email protected]>",
"Tim Kuehn <[email protected]>",
"Adam Wright <[email protected]>",
"Tim Kuehn <[email protected]>",
]
edition = "2021"
license = "MIT"
Expand All @@ -27,12 +27,12 @@ serde-transport-bincode = ["tokio-serde/bincode"]
tcp = ["tokio/net"]

full = [
"serde1",
"tokio1",
"serde-transport",
"serde-transport-json",
"serde-transport-bincode",
"tcp",
"serde1",
"tokio1",
"serde-transport",
"serde-transport-json",
"serde-transport-bincode",
"tcp",
]

[badges]
Expand All @@ -44,38 +44,32 @@ fnv = "1.0"
futures = "0.3"
humantime = "2.0"
pin-project = "1.0"
rand = "0.8"
serde = { optional = true, version = "1.0", features = ["derive"] }
static_assertions = "1.1.0"
tarpc-plugins = { path = "../plugins", version = "0.12" }
thiserror = "1.0"
tokio = { version = "1", features = ["time"] }
tokio = { version = "1", features = [] }
tokio-util = { version = "0.7.3", features = ["time"] }
tokio-serde = { optional = true, version = "0.8" }
tracing = { version = "0.1", default-features = false, features = [
"attributes",
"log",
"attributes",
"log",
] }
tracing-opentelemetry = { version = "0.17.2", default-features = false }
opentelemetry = { version = "0.17.0", default-features = false }


[dev-dependencies]
assert_matches = "1.4"
bincode = "1.3"
bytes = { version = "1", features = ["serde"] }
flate2 = "1.0"
futures-test = "0.3"
opentelemetry = { version = "0.17.0", default-features = false, features = [
"rt-tokio",
] }
opentelemetry-jaeger = { version = "0.16.0", features = ["rt-tokio"] }
pin-utils = "0.1.0-alpha"
serde_bytes = "0.11"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tokio = { version = "1", features = ["full", "test-util"] }
tokio = { version = "1", features = ["macros", "test-util"] }
tokio-serde = { version = "0.8", features = ["json", "bincode"] }
trybuild = "1.0"
wasm-bindgen = "0.2"
wasm-bindgen-test = "0.2"

[package.metadata.docs.rs]
all-features = true
Expand Down
Loading

0 comments on commit df610b8

Please sign in to comment.