Skip to content

Commit

Permalink
Merge pull request #129 from EspressoSystems/ma/async-std-default
Browse files Browse the repository at this point in the history
Default to async-std
  • Loading branch information
sveitser authored May 17, 2024
2 parents 298380a + ccf2d44 commit 27473ac
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 151 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ jobs:
strategy:
matrix:
flags:
- --cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\"
# no flags set, default to async-std
- ""
# crates that explicitly choose async-std should keep working
- --cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\"
- --cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"flume\"
- --cfg async_executor_impl=\"tokio\" --cfg async_channel_impl=\"tokio\"
- --cfg async_executor_impl=\"tokio\" --cfg async_channel_impl=\"flume\"
Expand Down Expand Up @@ -59,7 +62,6 @@ jobs:
runs-on: ubuntu-latest
env:
RUST_LOG: info
RUSTFLAGS: "--cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\""
steps:
- uses: actions/checkout@v4
- uses: katyo/publish-crates@v2
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/build_nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ on:
- cron: '0 0 * * 1'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
strategy:
matrix:
flags:
# no flags set, default to async-std
- ""
# crates that explicitly choose async-std should keep working
- --cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\"
- --cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"flume\"
- --cfg async_executor_impl=\"tokio\" --cfg async_channel_impl=\"tokio\"
Expand All @@ -18,11 +25,6 @@ jobs:
timeout-minutes: 60
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- uses: styfle/[email protected]
name: Cancel Outdated Builds
with:
all_but_latest: true
access_token: ${{ github.token }}

- name: Install Nix
uses: cachix/install-nix-action@v26
Expand All @@ -36,12 +38,12 @@ jobs:
- name: Build
run: |
nix develop -c RUSTFLAGS="${{ matrix.flags }}" cargo build --all-targets --workspace --release --features="logging-utils"
nix develop -c env RUSTFLAGS="${{ matrix.flags }}" cargo build --all-targets --workspace --release --features="logging-utils"
- name: Test
run: |
nix develop -c RUSTFLAGS="${{ matrix.flags }}" cargo test --all-targets --workspace --release --features="logging-utils"
nix develop -c env RUSTFLAGS="${{ matrix.flags }}" cargo test --all-targets --workspace --release --features="logging-utils"
- name: Lint
run: |
nix develop -c RUSTFLAGS="${{ matrix.flags }}" cargo clippy --all-targets --workspace --release --bins --tests --examples --features="logging-utils" -- -D warnings
nix develop -c env RUSTFLAGS="${{ matrix.flags }}" cargo clippy --all-targets --workspace --release --bins --tests --examples --features="logging-utils" -- -D warnings
2 changes: 1 addition & 1 deletion Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "async-compatibility-layer"
description = "an abstraction layer for using both async-std and tokio"
authors = ["Espresso Systems <[email protected]>"]
version = "1.1.0"
version = "1.2.0"
edition = "2021"
license = "MIT"

Expand Down Expand Up @@ -41,7 +41,7 @@ opentelemetry-jaeger = { version = "0.19.0", features = [
], optional = true }
opentelemetry-aws = { version = "0.8.0", features = ["trace"], optional = true }

[target.'cfg(all(async_executor_impl = "tokio"))'.dependencies]
[target.'cfg(async_executor_impl = "tokio")'.dependencies]
console-subscriber = { version = "0.2.0" }
tokio = { version = "1", features = [
"fs",
Expand All @@ -60,13 +60,13 @@ tokio = { version = "1", features = [
] }
tokio-stream = { version = "0.1.14" }

[target.'cfg(all(async_executor_impl = "async-std"))'.dependencies]
[target.'cfg(not(async_executor_impl = "tokio"))'.dependencies]
async-std = { version = "1.12", features = [
"attributes",
"unstable",
]}

[target.'cfg(all(async_channel_impl = "tokio"))'.dependencies]
[target.'cfg(async_channel_impl = "tokio")'.dependencies]
tokio = { version = "1", features = [
"fs",
"io-util",
Expand All @@ -84,7 +84,7 @@ tokio = { version = "1", features = [
] }
tokio-stream = { version = "0.1.14" }

[target.'cfg(all(async_channel_impl = "async-std"))'.dependencies]
[target.'cfg(not(any(async_channel_impl = "tokio", async_channel_impl = "flume")))'.dependencies]
async-std = { version = "1.12", features = [
"attributes",
"unstable",
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@

This crate exports four things:

- A compatibility/abstraction layer for writing async-executor agnostic code. We support two async executors: async-std and tokio. Each may be toggled with a configuration flag.
- A compatibility/abstraction layer for writing async channel agnostic code. We support three async channel implementations: async-std-channels. Each may be toggled with a configuration flag.
- A compatibility/abstraction layer for writing async-executor agnostic code. We
support two async executors: async-std and tokio. Each may be toggled with a
configuration flag.
- A compatibility/abstraction layer for writing async channel agnostic code. We
support three async channel implementations: async-std, tokio and flume. Each
may be toggled with a configuration flag.
- A library exporting a bunch of useful async primitives.
- A tracing configuration layer optionally supporting console and opentelemetry integration.

# Example usage
By default the `async-std` executor and channels are used.

To use tokio:

```bash
RUSTFLAGS='--cfg async_executor_impl="tokio" --cfg async_channel_impl="tokio"' cargo build
```

`async_executor_impl` may be either `tokio` or `async-std`. `async_channel_impl` may be either `tokio`, `async-std`, or `flume`. Note that using `tokio` channels requires `tokio` to be the runtime. Note that the async executor impl and async channel impl must be set in order for this crate to compile successfully.

`async_executor_impl` may be either `tokio` or `async-std`. `async_channel_impl`
may be either `tokio`, `async-std`, or `flume`.

Note that using `tokio` channels requires `tokio` to be the runtime.
109 changes: 61 additions & 48 deletions flake.lock

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

75 changes: 18 additions & 57 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,66 +1,27 @@
{
description = "Nll crate";
description = "A devShell example";

nixConfig = {
extra-substituters = [ "https://espresso-systems-private.cachix.org" ];
extra-trusted-public-keys = [
"espresso-systems-private.cachix.org-1:LHYk03zKQCeZ4dvg3NctyCq88e44oBZVug5LpYKjPRI="
];
};
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
inputs.flake-utils.url = "github:numtide/flake-utils";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
{ self, nixpkgs, flake-compat, utils, fenix }:
utils.lib.eachDefaultSystem (system:
outputs = { nixpkgs, rust-overlay, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
fenixStable = fenix.packages.${system}.stable.withComponents [
"cargo"
"clippy"
"rust-src"
"rustc"
"rustfmt"
"llvm-tools-preview"
];

CARGO_TARGET_DIR = "target_dirs/nix_rustc";

rustOverlay = final: prev: {
rustc = fenixStable;
cargo = fenixStable;
rust-src = fenixStable;
};

overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system;
overlays = [ rustOverlay ];
inherit system overlays;
};

buildDeps = with pkgs;
[
nixpkgs-fmt
fenix.packages.${system}.rust-analyzer
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
pkgs.libiconv
darwin.apple_sdk.frameworks.SystemConfiguration
in
with pkgs;
{
CARGO_TARGET_DIR = "target_dirs/nix_rustc";
devShells.default = mkShell {
buildInputs = [
just
rust-bin.stable.latest.default
];
in {
devShell = pkgs.mkShell {
inherit CARGO_TARGET_DIR;
buildInputs = [ fenixStable ] ++ buildDeps;
};

});
}
);
}
Loading

0 comments on commit 27473ac

Please sign in to comment.