Skip to content

Commit 27473ac

Browse files
authored
Merge pull request #129 from EspressoSystems/ma/async-std-default
Default to async-std
2 parents 298380a + ccf2d44 commit 27473ac

File tree

14 files changed

+161
-151
lines changed

14 files changed

+161
-151
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ jobs:
2424
strategy:
2525
matrix:
2626
flags:
27-
- --cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\"
27+
# no flags set, default to async-std
28+
- ""
29+
# crates that explicitly choose async-std should keep working
30+
- --cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\"
2831
- --cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"flume\"
2932
- --cfg async_executor_impl=\"tokio\" --cfg async_channel_impl=\"tokio\"
3033
- --cfg async_executor_impl=\"tokio\" --cfg async_channel_impl=\"flume\"
@@ -59,7 +62,6 @@ jobs:
5962
runs-on: ubuntu-latest
6063
env:
6164
RUST_LOG: info
62-
RUSTFLAGS: "--cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\""
6365
steps:
6466
- uses: actions/checkout@v4
6567
- uses: katyo/publish-crates@v2

.github/workflows/build_nix.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ on:
55
- cron: '0 0 * * 1'
66
workflow_dispatch:
77

8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
812
jobs:
913
build:
1014
strategy:
1115
matrix:
1216
flags:
17+
# no flags set, default to async-std
18+
- ""
19+
# crates that explicitly choose async-std should keep working
1320
- --cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\"
1421
- --cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"flume\"
1522
- --cfg async_executor_impl=\"tokio\" --cfg async_channel_impl=\"tokio\"
@@ -18,11 +25,6 @@ jobs:
1825
timeout-minutes: 60
1926
if: ${{ github.actor != 'dependabot[bot]' }}
2027
steps:
21-
- uses: styfle/[email protected]
22-
name: Cancel Outdated Builds
23-
with:
24-
all_but_latest: true
25-
access_token: ${{ github.token }}
2628

2729
- name: Install Nix
2830
uses: cachix/install-nix-action@v26
@@ -36,12 +38,12 @@ jobs:
3638
3739
- name: Build
3840
run: |
39-
nix develop -c RUSTFLAGS="${{ matrix.flags }}" cargo build --all-targets --workspace --release --features="logging-utils"
41+
nix develop -c env RUSTFLAGS="${{ matrix.flags }}" cargo build --all-targets --workspace --release --features="logging-utils"
4042
4143
- name: Test
4244
run: |
43-
nix develop -c RUSTFLAGS="${{ matrix.flags }}" cargo test --all-targets --workspace --release --features="logging-utils"
45+
nix develop -c env RUSTFLAGS="${{ matrix.flags }}" cargo test --all-targets --workspace --release --features="logging-utils"
4446
4547
- name: Lint
4648
run: |
47-
nix develop -c RUSTFLAGS="${{ matrix.flags }}" cargo clippy --all-targets --workspace --release --bins --tests --examples --features="logging-utils" -- -D warnings
49+
nix develop -c env RUSTFLAGS="${{ matrix.flags }}" cargo clippy --all-targets --workspace --release --bins --tests --examples --features="logging-utils" -- -D warnings

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "async-compatibility-layer"
33
description = "an abstraction layer for using both async-std and tokio"
44
authors = ["Espresso Systems <[email protected]>"]
5-
version = "1.1.0"
5+
version = "1.2.0"
66
edition = "2021"
77
license = "MIT"
88

@@ -41,7 +41,7 @@ opentelemetry-jaeger = { version = "0.19.0", features = [
4141
], optional = true }
4242
opentelemetry-aws = { version = "0.8.0", features = ["trace"], optional = true }
4343

44-
[target.'cfg(all(async_executor_impl = "tokio"))'.dependencies]
44+
[target.'cfg(async_executor_impl = "tokio")'.dependencies]
4545
console-subscriber = { version = "0.2.0" }
4646
tokio = { version = "1", features = [
4747
"fs",
@@ -60,13 +60,13 @@ tokio = { version = "1", features = [
6060
] }
6161
tokio-stream = { version = "0.1.14" }
6262

63-
[target.'cfg(all(async_executor_impl = "async-std"))'.dependencies]
63+
[target.'cfg(not(async_executor_impl = "tokio"))'.dependencies]
6464
async-std = { version = "1.12", features = [
6565
"attributes",
6666
"unstable",
6767
]}
6868

69-
[target.'cfg(all(async_channel_impl = "tokio"))'.dependencies]
69+
[target.'cfg(async_channel_impl = "tokio")'.dependencies]
7070
tokio = { version = "1", features = [
7171
"fs",
7272
"io-util",
@@ -84,7 +84,7 @@ tokio = { version = "1", features = [
8484
] }
8585
tokio-stream = { version = "0.1.14" }
8686

87-
[target.'cfg(all(async_channel_impl = "async-std"))'.dependencies]
87+
[target.'cfg(not(any(async_channel_impl = "tokio", async_channel_impl = "flume")))'.dependencies]
8888
async-std = { version = "1.12", features = [
8989
"attributes",
9090
"unstable",

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22

33
This crate exports four things:
44

5-
- 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.
6-
- 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.
5+
- A compatibility/abstraction layer for writing async-executor agnostic code. We
6+
support two async executors: async-std and tokio. Each may be toggled with a
7+
configuration flag.
8+
- A compatibility/abstraction layer for writing async channel agnostic code. We
9+
support three async channel implementations: async-std, tokio and flume. Each
10+
may be toggled with a configuration flag.
711
- A library exporting a bunch of useful async primitives.
812
- A tracing configuration layer optionally supporting console and opentelemetry integration.
913

1014
# Example usage
15+
By default the `async-std` executor and channels are used.
16+
17+
To use tokio:
1118

1219
```bash
1320
RUSTFLAGS='--cfg async_executor_impl="tokio" --cfg async_channel_impl="tokio"' cargo build
1421
```
1522

16-
`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.
17-
23+
`async_executor_impl` may be either `tokio` or `async-std`. `async_channel_impl`
24+
may be either `tokio`, `async-std`, or `flume`.
1825

26+
Note that using `tokio` channels requires `tokio` to be the runtime.

flake.lock

Lines changed: 61 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,27 @@
11
{
2-
description = "Nll crate";
2+
description = "A devShell example";
33

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

11-
inputs = {
12-
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
13-
utils.url = "github:numtide/flake-utils";
14-
flake-compat = {
15-
url = "github:edolstra/flake-compat";
16-
flake = false;
17-
};
18-
fenix = {
19-
url = "github:nix-community/fenix";
20-
inputs.nixpkgs.follows = "nixpkgs";
21-
};
22-
};
23-
24-
outputs =
25-
{ self, nixpkgs, flake-compat, utils, fenix }:
26-
utils.lib.eachDefaultSystem (system:
8+
outputs = { nixpkgs, rust-overlay, flake-utils, ... }:
9+
flake-utils.lib.eachDefaultSystem (system:
2710
let
28-
fenixStable = fenix.packages.${system}.stable.withComponents [
29-
"cargo"
30-
"clippy"
31-
"rust-src"
32-
"rustc"
33-
"rustfmt"
34-
"llvm-tools-preview"
35-
];
36-
37-
CARGO_TARGET_DIR = "target_dirs/nix_rustc";
38-
39-
rustOverlay = final: prev: {
40-
rustc = fenixStable;
41-
cargo = fenixStable;
42-
rust-src = fenixStable;
43-
};
44-
11+
overlays = [ (import rust-overlay) ];
4512
pkgs = import nixpkgs {
46-
inherit system;
47-
overlays = [ rustOverlay ];
13+
inherit system overlays;
4814
};
49-
50-
buildDeps = with pkgs;
51-
[
52-
nixpkgs-fmt
53-
fenix.packages.${system}.rust-analyzer
54-
] ++ lib.optionals stdenv.isDarwin [
55-
darwin.apple_sdk.frameworks.Security
56-
pkgs.libiconv
57-
darwin.apple_sdk.frameworks.SystemConfiguration
15+
in
16+
with pkgs;
17+
{
18+
CARGO_TARGET_DIR = "target_dirs/nix_rustc";
19+
devShells.default = mkShell {
20+
buildInputs = [
21+
just
22+
rust-bin.stable.latest.default
5823
];
59-
in {
60-
devShell = pkgs.mkShell {
61-
inherit CARGO_TARGET_DIR;
62-
buildInputs = [ fenixStable ] ++ buildDeps;
6324
};
64-
65-
});
25+
}
26+
);
6627
}

0 commit comments

Comments
 (0)