Skip to content

Commit

Permalink
ping/rust: Refactor into multiple binaries (#72)
Browse files Browse the repository at this point in the history
By having one Rust binary per version, we can vary the actual binary from
version to version and f.e. fix deprecated API calls. It does introduce a bit of
duplication between the different versions but I'd rather have that then not
being able to adapt the tests to new APIs.

Instead of activating a feature per libp2p version, we add them all as
dependencies. This ensures all transitive dependencies are properly tracked in
`Cargo.lock`. Additionally, this gives us a single place we are can activate all
the feature.

For `master` and pull-request builds, we replace the git target or rev with the
one coming from the CI build. Once we trigger a build, `cargo` will update and
resolve the necessary dependencies before that, thus fixing problems such as
libp2p/rust-libp2p#2972.
  • Loading branch information
thomaseizinger committed Nov 18, 2022
1 parent b97b36a commit abce1ee
Show file tree
Hide file tree
Showing 17 changed files with 1,293 additions and 338 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -35,11 +35,11 @@ When a new version of libp2p is released, we want to make it permanent in the `p
When a new version of libp2p is released, we want to make it permanent in the `ping/rust` test folder.

1. In the `ping/_compositions/rust.toml` file,
- Copy the latest `[[groups]]` section and update it's `Id` and `CargoFeature` name.
- Copy the latest `[[groups]]` section and update it's `Id` and `BinaryName` accordingly.
2. In the `ping/rust` folder,
- `Cargo.toml`: create the feature flags `libp2pvxxx` with the released version,
- `src/main.rs`: Update the `mod libp2p` definition with the new version,
- Run `cargo update` if needed. Try to build with `cargo build --features libp2pvxxx`
- `Cargo.toml`: Add the newly released version as a crates.io dependency.
- `Cargo.toml`: Update the `Next release` dependency to the latest `master` SHA.
- `src/bin`: Add a new binary with the next released version.
3. Run the test on your machine
- Do once, from the test-plans root: import the test-plans with `testground plan import --from ./ --name libp2p`
- Run the test with `testground run composition -f ping/_compositions/rust-cross-versions.toml --wait`
Expand Down
10 changes: 4 additions & 6 deletions ping/_compositions/go-rust-interop-latest.toml
Expand Up @@ -75,7 +75,7 @@
path = "./rust/"

[groups.build_config.build_args]
CARGO_FEATURES = '{{ .CargoFeatures }}'
BINARY_NAME = '{{ .BinaryName }}'
{{ end }}

{{ if eq $.Env.InteropTarget "rust" }}
Expand All @@ -90,11 +90,9 @@
path = "./rust/"

[groups.build_config.build_args]
CARGO_FEATURES = '{{ .CargoFeatures }}'
CARGO_REMOVE = '{{ .CargoFeatures }}'
CARGO_PATCH = """
{{ .CargoFeatures }} = {package = "libp2p", git = "https://{{ or $.Env.GitTarget "github.com/libp2p/rust-libp2p" }}", rev = "{{ $.Env.GitReference }}", default_features = false, features = [ "websocket", "mplex", "yamux", "tcp", "ping", "noise", "dns", "async-std", "rsa" ], optional = true}
"""
BINARY_NAME = '{{ .BinaryName }}'
GIT_TARGET = '{{ $.Env.GitTarget }}'
GIT_REF = '{{ $.Env.GitTarget }}'
{{ end }}
{{ end }}
{{ end }}
Expand Down
13 changes: 6 additions & 7 deletions ping/_compositions/go-rust-interop.toml
Expand Up @@ -102,7 +102,7 @@
path = "./rust/"

[groups.build_config.build_args]
CARGO_FEATURES = '{{ .CargoFeatures }}'
BINARY_NAME = '{{ .BinaryName }}'
{{ end }}

{{ with .master }}
Expand All @@ -115,7 +115,8 @@
path = "./rust/"

[groups.build_config.build_args]
CARGO_FEATURES = '{{ .CargoFeatures }}'
BINARY_NAME = '{{ .BinaryName }}'
GIT_REV = '{{ $.Env.GitReference }}'
{{ end }}

{{ if eq $.Env.InteropTarget "rust" }}
Expand All @@ -130,11 +131,9 @@
path = "./rust/"

[groups.build_config.build_args]
CARGO_FEATURES = '{{ .CargoFeatures }}'
CARGO_REMOVE = '{{ .CargoFeatures }}'
CARGO_PATCH = """
{{ .CargoFeatures }} = {package = "libp2p", git = "https://{{ or $.Env.GitTarget "github.com/libp2p/rust-libp2p" }}", rev = "{{ $.Env.GitReference }}", default_features = false, features = [ "websocket", "mplex", "yamux", "tcp", "ping", "noise", "dns", "async-std", "rsa" ], optional = true}
"""
BINARY_NAME = '{{ .BinaryName }}'
GIT_TARGET = '{{ $.Env.GitTarget }}'
GIT_REV = '{{ $.Env.GitReference }}'
{{ end }}
{{ end }}
{{ end }}
Expand Down
13 changes: 6 additions & 7 deletions ping/_compositions/rust-cross-versions.toml
Expand Up @@ -15,7 +15,7 @@
instances = { count = 1 }

[groups.build_config.build_args]
CARGO_FEATURES = '{{ .CargoFeatures }}'
BINARY_NAME = '{{ .BinaryName }}'
{{ end }}

{{ with .master }}
Expand All @@ -24,7 +24,8 @@
instances = { count = 1 }

[groups.build_config.build_args]
CARGO_FEATURES = '{{ .CargoFeatures }}'
BINARY_NAME = '{{ .BinaryName }}'
GIT_REF = '{{ $.Env.GitTarget }}'
{{ end }}

{{ if $.Env.GitReference }}
Expand All @@ -34,11 +35,9 @@
instances = { count = 1 }

[groups.build_config.build_args]
CARGO_FEATURES = '{{ .CargoFeatures }}'
CARGO_REMOVE = '{{ .CargoFeatures }}'
CARGO_PATCH = """
{{ .CargoFeatures }} = {package = "libp2p", git = "https://{{ or $.Env.GitTarget "github.com/libp2p/rust-libp2p" }}", rev = "{{ $.Env.GitReference }}", default_features = false, features = [ "websocket", "mplex", "yamux", "tcp", "ping", "noise", "dns", "async-std", "rsa" ], optional = true}
"""
BINARY_NAME = '{{ .BinaryName }}'
GIT_TARGET = '{{ $.Env.GitTarget }}'
GIT_REF = '{{ $.Env.GitTarget }}'
{{ end }}
{{ end }}
{{ end }}
16 changes: 8 additions & 8 deletions ping/_compositions/rust.toml
@@ -1,29 +1,29 @@
[master]
CargoFeatures = 'libp2pmaster'
BinaryName = 'testplan_0500'

[custom]
CargoFeatures = 'libp2pmaster'
BinaryName = 'testplan_0500'

[[groups]]
Id = '0.49.0'
CargoFeatures = 'libp2pv0490'
BinaryName = 'testplan_0490'

[[groups]]
Id = '0.48.0'
CargoFeatures = 'libp2pv0480'
BinaryName = 'testplan_0480'

[[groups]]
Id = "v0.47.0"
CargoFeatures = 'libp2pv0470'
BinaryName = 'testplan_0470'

[[groups]]
Id = "v0.46.0"
CargoFeatures = 'libp2pv0460'
BinaryName = 'testplan_0460'

[[groups]]
Id = "v0.45.1"
CargoFeatures = 'libp2pv0450'
BinaryName = 'testplan_0450'

[[groups]]
Id = "v0.44.0"
CargoFeatures = 'libp2pv0440'
BinaryName = 'testplan_0440'
3 changes: 3 additions & 0 deletions ping/rust/.dockerignore
@@ -0,0 +1,3 @@
target/
Dockerfile
manifest.toml

0 comments on commit abce1ee

Please sign in to comment.