Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion driver/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl Check<'_> {
}
cmd
};
run_cargo(cargo("clean").arg("--quiet"))?;
run_cargo(cargo("clean").arg("--quiet").args(resolution(self.args)))?;
// Its own, since runs may share a target directory.
let ran = target_dir.join(format!("{}-{}.ran", self.tool, std::process::id()));
match std::fs::remove_file(&ran) {
Expand Down Expand Up @@ -180,6 +180,22 @@ fn run_cargo(cmd: &mut Command) -> Result<(), String> {
}
}

/// The cargo args that pick how the workspace resolves, which `cargo clean` resolves it
/// by too: `--config`, and the lockfile and network flags.
fn resolution(args: &[String]) -> Vec<&str> {
let mut picked = Vec::new();
let mut args = args.iter().map(String::as_str);
while let Some(arg) = args.next() {
match arg {
"--locked" | "--frozen" | "--offline" => picked.push(arg),
"--config" => picked.extend([Some(arg), args.next()].into_iter().flatten()),
_ if arg.starts_with("--config=") => picked.push(arg),
_ => {}
}
}
picked
}

/// The directory of the workspace `manifest`, or the current directory, belongs to.
fn workspace_root(manifest: Option<&Path>) -> Result<PathBuf, String> {
let mut cmd = cargo();
Expand Down
15 changes: 11 additions & 4 deletions ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ all and an export names another's types across crates. `--out` writes a crate of
libraries, its runtime beside it, and the header in `include/<prefix>.h`; `cargo build`
on that crate makes a static and a shared library. That crate enables each export's
features as the check did, including `--features <export>/<feature>`; such a feature on a
dependency that is no export is an error.
dependency that is no export is an error. It resolves them as the check did, wherever it
is built: its manifest carries, as a `[patch]`, each patch or `[replace]` cargo applied
to what the library builds with on any platform, read off cargo's resolution, wherever
it was declared (the manifest, cargo's config, `--config`, or the environment), keyed by
its source's URL.
A `[replace]` from the source it replaces, which no `[patch]` can carry, is an error.

```toml
# ffi.toml, beside the package's Cargo.toml unless --manifest-path says otherwise.
Expand Down Expand Up @@ -128,7 +133,7 @@ rest. It ignores the config's `exclude`.

```bash
just ffi test # export the fixtures, build them, and drive api from C
just ffi moq # export moq-net and its exports at the pinned revision, build them, and run moq/moq.c
just ffi moq # export moq's crates at the pinned revision, build them, and run moq/moq.c
just ffi census # census each into target/census
nix develop .#bench --command just ffi bench # frame writes, through the export and moq's rs/moq-c
```
Expand All @@ -138,5 +143,7 @@ export into the same library. `tests/api.c` runs the same script as the
fixture's `examples/transcript.rs`, and the two transcripts must match line for line;
then it breaks each runtime check, which must abort with its message. The `reject`
fixture's expected errors, each with its notes, are `fixtures/reject/expected.txt`.
moq-net's `moq/moq.c` publishes and subscribes to a track in one process, polling each
read, and scopes an origin to moq-pattern's patterns.
moq's crates export through `target/moq-ffi`, an empty library on each that `just ffi moq`
writes in place of moq-ffi's remainder. `moq/moq.c` publishes and subscribes to a moq-net
track in one process, polling each read, scopes an origin to moq-pattern's patterns, and
reads an OpusHead into hang's catalog through moq-mux.
55 changes: 37 additions & 18 deletions ffi/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,8 @@ run *args:
cargo run --locked --quiet -- {{ args }}

# Census each package moq/ffi.toml exports into target/census/<package>.md, from the moq revision `just ts moq` pins or a checkout.
census checkout="":
#!/usr/bin/env bash
set -euo pipefail
src="{{ checkout }}"
if [ -z "$src" ]; then
(cd ../ts && just moq-pin)
src=../ts/target/moq
fi
cargo run --locked --quiet -- --config moq/ffi.toml --manifest-path "$src/rs/moq-net/Cargo.toml" --census target/census
census checkout="": (standin checkout)
cargo run --locked --quiet -- --config moq/ffi.toml --manifest-path target/moq-ffi/Cargo.toml --census target/census

# Time frame writes through the export and through moq's hand-written rs/moq-c, in the bench shell: nix develop .#bench.
bench checkout="": (moq checkout)
Expand All @@ -62,19 +55,45 @@ bench checkout="": (moq checkout)
target/bench-export
done

# Export moq-net's C ABI, build it, and run moq/moq.c against it, from the moq revision `just ts moq` pins or a checkout.
moq checkout="":
# Export moq's crates' C ABI, build it, and run moq/moq.c against it, from the moq revision `just ts moq` pins or a checkout.
moq checkout="": (standin checkout)
#!/usr/bin/env bash
set -euo pipefail
out=target/export/moq
cargo run --locked --quiet -- --config moq/ffi.toml --manifest-path target/moq-ffi/Cargo.toml --out "$out"
# The lockfile the check resolved with pins what the export depends on.
cp target/moq-ffi/Cargo.lock "$out/Cargo.lock"
cargo build --quiet --release --manifest-path "$out/Cargo.toml"
cc -std=c11 -pedantic -Wall -Wextra -Werror -I "$out/include" moq/moq.c "$out/target/release/libmoq.a" -lpthread -ldl -lm -o target/moq-test
target/moq-test

# Write target/moq-ffi, an empty library on every crate moq/ffi.toml exports, from the moq revision `just ts moq` pins or a checkout: the check builds with all of them, as moq-ffi's remainder will.
[private]
standin checkout="":
#!/usr/bin/env bash
set -euo pipefail
src="{{ checkout }}"
if [ -z "$src" ]; then
(cd ../ts && just moq-pin)
src=../ts/target/moq
fi
out=target/export/moq
cargo run --locked --quiet -- --config moq/ffi.toml --manifest-path "$src/rs/moq-net/Cargo.toml" --out "$out"
# moq's lockfile pins what the export depends on, as it pins moq-net's own build.
cp "$src/Cargo.lock" "$out/Cargo.lock"
cargo build --quiet --release --manifest-path "$out/Cargo.toml"
cc -std=c11 -pedantic -Wall -Wextra -Werror -I "$out/include" moq/moq.c "$out/target/release/libmoq.a" -lpthread -ldl -lm -o target/moq-test
target/moq-test
src=$(realpath "$src")
dir=target/moq-ffi
# moq-ffi's dependencies among the exports, moq-tokio with its default features as
# moq-ffi has them, and moq-pattern, which moq-ffi reaches through moq-net.
exports=(hang moq-clock moq-mux moq-net moq-pattern moq-tokio)
mkdir -p "$dir/src"
{
printf '# Generated by just ffi standin, from %s.\n' "$src"
printf '[package]\nname = "moq-ffi"\nversion = "0.0.0"\nedition = "2024"\npublish = false\n\n[dependencies]\n'
for name in "${exports[@]}"; do
printf '%s = { path = "%s/rs/%s" }\n' "$name" "$src" "$name"
done
printf '\n[workspace]\n'
} > "$dir/Cargo.toml"
# rustc loads a dependency only once the crate names it.
for name in "${exports[@]}"; do
printf 'use %s as _;\n' "${name//-/_}"
done > "$dir/src/lib.rs"
# moq's lockfile pins what moq's own builds use.
cp "$src/Cargo.lock" "$dir/Cargo.lock"
Loading