diff --git a/driver/src/cargo.rs b/driver/src/cargo.rs index 348961405..79697a1e3 100644 --- a/driver/src/cargo.rs +++ b/driver/src/cargo.rs @@ -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) { @@ -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 { let mut cmd = cargo(); diff --git a/ffi/README.md b/ffi/README.md index f53fc72bd..a7579ff7d 100644 --- a/ffi/README.md +++ b/ffi/README.md @@ -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/.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 /`; 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. @@ -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 ``` @@ -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. diff --git a/ffi/justfile b/ffi/justfile index a55080d93..34157080b 100644 --- a/ffi/justfile +++ b/ffi/justfile @@ -34,15 +34,8 @@ run *args: cargo run --locked --quiet -- {{ args }} # Census each package moq/ffi.toml exports into target/census/.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) @@ -62,8 +55,21 @@ 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 }}" @@ -71,10 +77,23 @@ moq checkout="": (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" diff --git a/ffi/moq/ffi.toml b/ffi/moq/ffi.toml index d68100c67..a95f847db 100644 --- a/ffi/moq/ffi.toml +++ b/ffi/moq/ffi.toml @@ -1,5 +1,9 @@ -package = "moq-net" +package = "moq-ffi" prefix = "moq" + +# moq-net, and each package below, exported into one library through the stand-in for +# moq-ffi's remainder that `just ffi standin` writes, which builds with them all. +[crates.moq-net] # What the export refuses at the pinned revision, as `just ffi census` lists it: the API # a hand-written wrapper still has to cover. exclude = [ @@ -24,7 +28,6 @@ exclude = [ "Server::accept", "Server::accept_request", "Server::with_publisher", - "Session", "Timed", "Timestamp::as_micros", "Timestamp::as_millis", @@ -34,15 +37,11 @@ exclude = [ "Versions::iter", "announce::Announce", "announce::Consumer::poll_synced", - "auth::Issued", - "auth::Request", - "auth::Requests", "bytes", "cache::Pool::poll", "frame::Buffer", "frame::Producer::group", - "goaway::Consumer", - "goaway::Producer", + "goaway::Consumer::poll", "group::Consumer::poll_read_frames", "group::Consumer::read_frames", "group::Producer::write_frames", @@ -101,7 +100,7 @@ exclude = [ "varint::encode_quic", ] -[rename] +[crates.moq-net.rename] # The rule makes both this type and `Session::stats` `moq_session_stats`. "session::Stats" = "session_stats_snapshot" # The rule makes both this type and `Path::relative` `moq_path_relative`. @@ -133,3 +132,377 @@ exclude = [ "wall" = "now_wall" # The rule makes both this function and the type `Interval` `moq_interval`. "interval" = "interval_every" + +[crates.moq-tokio] +exclude = [ + "Addrs", + # Not refused: each names both a field and a method, whose getters `rename` cannot + # tell apart, so both are left out. + "Backoff::initial", + "Backoff::max", + "Backoff::timeout", + "Client::connect", + "Client::with_publisher", + "Listener::accept_health", + "Listener::local_addr", + "Listener::tcp_local_addr", + "Listener::websocket_local_addr", + "Log::level", + "Log::new", + "RedactedUrl", + "Server::accept_health", + "Server::local_addr", + "Server::websocket_local_addr", + "accept::Failure::ALL", + "accept::Failure::classify", + "accept::Health::failed", + "accept::Health::new", + "bind", + "cli::Answer::exit", + "cli::Deprecated::changed", + "cli::Deprecated::flag", + "cli::Deprecated::toml", + "cli::FileSource", + "cli::Merge", + "cli::UnknownEnv", + "cli::answer", + "cli::check_env", + "cli::usage_rs", + "connect::Addr", + "connect::Config::bind", + "connect::Config::tokens", + "connect::Config::url", + "connect::Config::version", + "connect::EmptyToken", + "connect::Resolved::bind", + "connect::Token", + "connect::Tokens::set", + "connection::Monitor::poll_presence", + "crypto::install_default", + "crypto::provider", + "failover::Attempt", + "listen::Config::preferred_v4", + "listen::Config::preferred_v6", + "listen::Config::version", + "listen::Reset::secret", + "notify", + "panic::isolate", + "panic::message", + "quic::Config::keylog", + "quic::Config::qlog", + "quic::Error", + "quic::Limits", + "quic::LimitsError", + "quic::Resolved::keylog", + "quic::Resolved::qlog", + "quic::driver::AckFrequencyConfig", + "quic::driver::ApplicationClose", + "quic::driver::AsyncUdpSocket", + "quic::driver::Chunk", + "quic::driver::ClientConfig", + "quic::driver::ClosedStream", + "quic::driver::ConfigError", + "quic::driver::ConnectError", + "quic::driver::Connecting", + "quic::driver::Connection::accept_bi", + "quic::driver::Connection::accept_uni", + "quic::driver::Connection::authenticated", + "quic::driver::Connection::close", + "quic::driver::Connection::close_reason", + "quic::driver::Connection::closed", + "quic::driver::Connection::congestion_state", + "quic::driver::Connection::handshake_data", + "quic::driver::Connection::open_bi", + "quic::driver::Connection::open_uni", + "quic::driver::Connection::peer_identity", + "quic::driver::Connection::read_datagram", + "quic::driver::Connection::remote_address", + "quic::driver::Connection::send_datagram", + "quic::driver::Connection::set_limits", + "quic::driver::Connection::stats", + "quic::driver::ConnectionClose", + "quic::driver::ConnectionError", + "quic::driver::ConnectionId", + "quic::driver::ConnectionIdGenerator", + "quic::driver::ConnectionStats", + "quic::driver::Dir", + "quic::driver::EcnCodepoint", + "quic::driver::Endpoint", + "quic::driver::EndpointConfig", + "quic::driver::FrameStats", + "quic::driver::FrameType", + "quic::driver::IdleTimeout", + "quic::driver::Incoming", + "quic::driver::InvalidCid", + "quic::driver::Lease", + "quic::driver::MtuDiscoveryConfig", + "quic::driver::PathStats", + "quic::driver::ReadError", + "quic::driver::ReadExactError", + "quic::driver::ReadToEndError", + "quic::driver::RecvStream", + "quic::driver::ResetError", + "quic::driver::SendDatagramError", + "quic::driver::SendStream", + "quic::driver::ServerConfig", + "quic::driver::StoppedError", + "quic::driver::StreamId", + "quic::driver::Transmit", + "quic::driver::TransportConfig", + "quic::driver::TransportErrorCode", + "quic::driver::UdpSender", + "quic::driver::UdpStats", + "quic::driver::ValidationTokenConfig", + "quic::driver::VarInt", + "quic::driver::VarIntBoundsExceeded", + "quic::driver::WriteError", + "quic::driver::Written", + "quic::driver::crypto", + "rustls", + "secret::Secret::as_bytes", + "server::Config::websocket", + "server::Link::local", + "server::Link::remote", + "server::Request::local_addr", + "server::Request::remote_addr", + "server::Request::url", + "server::Request::with_publisher", + "server::Request::within", + "tcp::Config::bind", + "tcp::Error", + "tcp::Listener", + "tls::Certificates::fingerprints", + "tls::Connect::build", + "tls::Connect::cert", + "tls::Connect::fingerprint", + "tls::Connect::key", + "tls::Connect::root", + "tls::Identity::generate", + "tls::KeyLog", + "tls::Listen::cert", + "tls::Listen::generate", + "tls::Listen::key", + "tls::Listen::load_roots", + "tls::Listen::root", + "tls::Listen::server_config", + "tls::PeerIdentity::chain", + "tls::PeerIdentity::from_chain", + "tls::Serve::config", + "tls::Serve::resolver", + "tls::parse_fingerprint", + "transport::Error", + "transport::RecvStream", + "transport::SendStream", + "transport::Session", + "unix::Allow::gid", + "unix::Allow::pid", + "unix::Allow::uid", + "unix::Config::bind", + "unix::Listener::accept", + "unix::Listener::path", + "unix::Listener::with_protocols", + "watch::Files", + "websocket::Error", + "websocket::Listener", + "websocket::Options", + "websocket::accept", + "worker::Group::finished", + "worker::Group::local_addr", + "worker::Group::members", + "worker::Member", + "worker::Spawner", + "worker::Workers::local_addr", +] + +[crates.moq-tokio.rename] +# The rule names these and moq-net's `Client`, `Server`, and `Error` alike. +"Client" = "tokio_client" +"Server" = "tokio_server" +"Error" = "tokio_error" +# The rule makes both this enum and `ConnectError` `moq_connect_error`. +"connect::Error" = "connect_target_error" +# The rule makes both this type and `Connection::monitor` `moq_connection_monitor`. +"connection::Monitor" = "monitor" + +[crates.hang] +exclude = [ + "Catalog", + "catalog::Archive::store", + "catalog::Archive::timelines", + "catalog::Audio::enabled", + "catalog::Audio::ranked", + "catalog::Audio::renditions", + "catalog::Binary::tracks", + "catalog::BinaryConfig::extra", + "catalog::Consumer", + "catalog::H265", + "catalog::Json::tracks", + "catalog::JsonConfig::extra", + "catalog::Reference", + "catalog::Text::renditions", + "catalog::UnknownContainer", + "catalog::UnknownProjection", + "catalog::Video::enabled", + "catalog::Video::ranked", + "catalog::Video::renditions", + "container::Frame::encode", + "echo::Snapshot", + "health::Connection::evidence", + "health::Evidence", + "health::Health", + "health::Limits", + "health::PublisherThresholds::skipped", + "health::Rendition::evidence", + "health::Report", + "health::Sample", + "health::TransportThresholds::headroom", + "health::TransportThresholds::loss", + "health::TransportThresholds::rtt", + "health::ViewerThresholds::errors", + "health::ViewerThresholds::late", + "health::ViewerThresholds::stalled", + "health::publisher", + "health::viewer", + "stats::Snapshot", + "timeline::Record", + "timeline::RecordExt", +] + +[crates.hang.rename] +# The rule names this and moq-net's `Error` alike. +"Error" = "hang_error" +# The rule makes both these enums and the `kind` methods of `AudioCodec` and `VideoCodec` +# `moq_catalog__codec_kind`. +"catalog::AudioCodecKind" = "audio_codec_kind" +"catalog::VideoCodecKind" = "video_codec_kind" + +[crates.moq-mux] +exclude = [ + "Linger", + "Source::bind", + "Source::catalog", + "Source::follow", + "Source::resolve", + "Source::resolve_reference", + "Source::stats", + "Source::subscribe_track", + "binary::Consumer::latest", + "binary::Consumer::next", + "binary::Consumer::poll_latest", + "binary::Consumer::poll_next", + "binary::Snapshot", + "binary::Stream", + "catalog::Config", + "catalog::Consumer", + "catalog::Entry", + "catalog::Guard", + "catalog::IntoRendition", + "catalog::Producer", + "catalog::RenditionConfig", + "catalog::Reserved", + "catalog::Select", + "catalog::Stream", + "catalog::Timebase", + "catalog::hang::CatalogExt", + "catalog::hang::Consumer", + "catalog::hang::Extra::get", + "catalog::hang::Extra::iter", + "catalog::hang::Extra::remove", + "catalog::hang::Extra::set", + "catalog::msf::Consumer", + "codec::aac::Config::parse", + "codec::aac::Import", + "codec::annexb::NalIterator", + "codec::annexb::build_prefix", + "codec::annexb::find_start_code", + "codec::annexb::from_length_prefixed", + "codec::annexb::length_prefixed_to_annexb", + "codec::av1::Error", + "codec::av1::Import", + "codec::av1::Split::decode", + "codec::av1::Split::flush", + "codec::flac::Config", + "codec::flac::Import", + "codec::h264::Avcc::pps", + "codec::h264::Avcc::sps", + "codec::h264::Export", + "codec::h264::Import", + "codec::h264::Split::decode", + "codec::h264::Split::flush", + "codec::h265::Export", + "codec::h265::Hvcc::pps", + "codec::h265::Hvcc::sps", + "codec::h265::Hvcc::vps", + "codec::h265::Import", + "codec::h265::Split::decode", + "codec::h265::Split::flush", + "codec::mp3::Import", + "codec::opus::Config::parse", + "codec::opus::Import", + "codec::opus::Mapping::new", + "codec::opus::mapping::Config", + "codec::vp8::Import", + "codec::vp9::Import", + "container::Consumer", + "container::Container", + "container::GroupConsumer", + "container::InvalidEnd", + "container::MissingKeyframe", + "container::Producer", + "container::flv::Export", + "container::flv::Import", + "container::fmp4::Export", + "container::fmp4::Fragmenter::push", + "container::fmp4::Fragmenter::push_group", + "container::fmp4::Import", + "container::fmp4::Muxer::fragment", + "container::fmp4::Muxer::read", + "container::fmp4::Wire::new", + "container::fmp4::Wire::trak", + "container::fmp4::mp4_atom", + "container::mkv::Error", + "container::mkv::Export", + "container::mkv::Import", + "container::ts::Catalog", + "container::ts::Export", + "container::ts::Follower", + "container::ts::Import", + "container::ts::Mpegts::program_descriptors", + "container::ts::Mpegts::si", + "container::ts::Mpegts::tracks", + "container::ts::MultipleProgramsError", + "container::ts::Passthrough", + "container::ts::Programs", + "container::ts::Track::descriptors", + "container::ts::stats::Export::streams", + "container::ts::stats::Snapshot::streams", + "follow::Event", + "follow::Instances", + "import::Container", + "import::Track", + "import::TrackStream", + "json::Consumer", + "json::Snapshot", + "json::Stream", + "select::Broadcast::retain", + "timeline::Consumer", + "timeline::Entry", + "timeline::Event", + "timeline::Producer::push", +] + +[crates.moq-mux.rename] +# The rule names these and moq-net's `Error` and hang's `container::Frame` alike. +"Error" = "mux_error" +"container::Frame" = "mux_container_frame" +# The rule makes both this constant and `CatalogFormat`'s `Default` `moq_catalog_catalog_format_default`. +"catalog::CatalogFormat::DEFAULT" = "catalog_catalog_format_fallback" +# The rule makes both this constant and the method `Clock::timescale` `moq_clock_timescale`. +"Clock::TIMESCALE" = "clock_fixed_timescale" +# The rule makes each of these functions and its module's `Config` `moq_codec__config`. +"codec::aac::config" = "codec_aac_audio_config" +"codec::mp3::config" = "codec_mp3_audio_config" +"codec::opus::config" = "codec_opus_audio_config" +# The rule makes these methods and the variants' tags `moq_container_fmp4_chunk_`. +"container::fmp4::Chunk::init" = "container_fmp4_chunk_into_init" +"container::fmp4::Chunk::fragment" = "container_fmp4_chunk_into_fragment" diff --git a/ffi/moq/moq.c b/ffi/moq/moq.c index 31d267d94..6aae8630a 100644 --- a/ffi/moq/moq.c +++ b/ffi/moq/moq.c @@ -1,6 +1,7 @@ -/* moq-net's exported C API against the real library: a broadcast's track, published - * and subscribed to in one process, with every read polled as a future, and an origin. - * moq-pattern and moq-clock export into the same library, and moq-net names their types. +/* moq's exported C API against the real library: a broadcast's track, published and + * subscribed to in one process, with every read polled as a future, and an origin. + * moq-pattern, moq-clock, moq-tokio, hang, and moq-mux export into the same library, and + * each names the others' types. * * It needs no runtime: the waker counts wakes, and each poll that must wait is polled * again after the write that wakes it. */ @@ -183,6 +184,34 @@ int main(void) { moq_origin_driver_free(driver); moq_origin_producer_free(origin); + /* moq-mux reads an OpusHead into hang's catalog config: 44.1 kHz in, stereo, which + * the catalog lists at the decoder's 48 kHz, keeping the head as its description. */ + static const uint8_t head[] = {'O', 'p', 'u', 's', 'H', 'e', 'a', 'd', 1, 2, 0x38, 0x01, 0x44, 0xac, 0, 0, 0, 0, 0}; + moq_catalog_audio_config *audio = NULL; + moq_mux_error *mux_err = NULL; + CHECK(moq_codec_opus_audio_config((moq_buf){.ptr = head, .len = sizeof head}, &audio, &mux_err)); + CHECK(moq_catalog_audio_config_sample_rate(audio) == 48000); + CHECK(moq_catalog_audio_config_channel_count(audio) == 2); + moq_catalog_audio_codec codec = moq_catalog_audio_config_codec(audio); + CHECK(codec.tag == MOQ_CATALOG_AUDIO_CODEC_OPUS); + moq_catalog_audio_codec_free(&codec); + moq_buf description = moq_catalog_audio_config_description(audio); + CHECK(description.len == sizeof head && memcmp(description.ptr, head, sizeof head) == 0); + moq_buf_free(description); + moq_catalog_audio_config_free(audio); + /* A truncated head is moq-mux's error. */ + CHECK(!moq_codec_opus_audio_config((moq_buf){.ptr = head, .len = 8}, &audio, &mux_err)); + CHECK(mux_err != NULL); + moq_buf message = moq_mux_error_to_string(mux_err); + CHECK(message.len > 0); + moq_buf_free(message); + moq_mux_error_free(mux_err); + + /* moq-tokio's terminal connect errors, which moq-net's `Error` shares no names with. */ + moq_connect_error unauthorized = MOQ_CONNECT_ERROR_UNAUTHORIZED; + CHECK(moq_connect_error_is_auth(&unauthorized)); + CHECK(is(moq_connect_error_to_string(&unauthorized), "unauthorized")); + if (failures == 0) { printf("ok\n"); } diff --git a/ffi/src/cli.rs b/ffi/src/cli.rs index d5b53a1d0..10f94dd83 100644 --- a/ffi/src/cli.rs +++ b/ffi/src/cli.rs @@ -58,7 +58,7 @@ fn try_run(args: &[String]) -> Result { } /// Each export's package, as [`config::env::CRATES`] lists them: the configured package -/// first. Then its workspace's patches, as [`config::env::PATCH`] has them. +/// first. Then the patches it resolved with, as [`config::env::PATCH`] has them. fn crates(manifest: &Path, config: &Config, cargo: &[String]) -> Result<(String, String), String> { let picks = Picks::parse(cargo)?; // On the host, so the resolved dependencies are the ones the check passes rustc. @@ -159,48 +159,123 @@ fn crates(manifest: &Path, config: &Config, cargo: &[String]) -> Result<(String, } lines.push_str(&package.line()); } - Ok((lines, patches(&metadata.workspace_root)?)) + // Every platform's dependencies, which cargo resolves wherever the glue builds. + let output = run_cargo(manifest, &["metadata", "--format-version", "1"], &picks)?; + let resolved: Metadata = serde_json::from_slice(&output).map_err(|err| format!("reading cargo metadata: {err}"))?; + Ok((lines, overrides(&resolved, top)?)) } -/// The workspace's `[patch]` and `[replace]` tables, with each path absolute, so the -/// glue's own workspace resolves the exports as the check does. -fn patches(root: &Path) -> Result { - let manifest = root.join("Cargo.toml"); - let text = std::fs::read_to_string(&manifest).map_err(|err| format!("reading {}: {err}", manifest.display()))?; - let table: toml::Table = text - .parse() - .map_err(|err| format!("parsing {}: {err}", manifest.display()))?; - toml::to_string(&overrides(&table, root)) - .map_err(|err| format!("writing the patches of {}: {err}", manifest.display())) +/// The `[patch]` the glue's workspace resolves the exports by as the check did, wherever +/// it builds, as TOML with each path absolute. +fn overrides(metadata: &Metadata, top: &Package) -> Result { + let patch = patch(metadata, top)?; + let mut overrides = toml::Table::new(); + if !patch.is_empty() { + overrides.insert("patch".to_string(), patch.into()); + } + toml::to_string(&overrides).map_err(|err| format!("writing the patches: {err}")) } -/// A manifest's `[patch.]` and `[replace]` dependencies, each path made absolute -/// from `root`, the manifest's directory. -fn overrides(manifest: &toml::Table, root: &Path) -> toml::Table { - let mut overrides = manifest.clone(); - overrides.retain(|key, _| key == "patch" || key == "replace"); - let mut deps: Vec<&mut toml::Value> = Vec::new(); - for (key, value) in overrides.iter_mut() { - let Some(table) = value.as_table_mut() else { +/// Each patch cargo applied in resolving what `top` builds with on any platform, wherever +/// it was declared: the manifest, cargo's config, `--config`, or the environment. A +/// dependency resolved to a package of another source than the one it names was patched, +/// or `[replace]`d by a package of the same version, which a patch resolves to alike; it +/// is keyed by the URL of the source it names, which reads the same without that config. +fn patch(metadata: &Metadata, top: &Package) -> Result { + let packages: BTreeMap<&str, &Package> = metadata.packages.iter().map(|p| (p.id.as_str(), p)).collect(); + let nodes: BTreeMap<&str, &Node> = metadata.resolve.nodes.iter().map(|n| (n.id.as_str(), n)).collect(); + let mut patch = toml::Table::new(); + let mut seen = BTreeSet::new(); + let mut queue = vec![top.id.as_str()]; + while let Some(id) = queue.pop() { + let (true, Some(package), Some(node)) = (seen.insert(id), packages.get(id), nodes.get(id)) else { continue; }; - match key.as_str() { - // A table of dependencies for each source. - "patch" => deps.extend( - (table.iter_mut()) - .filter_map(|(_, source)| source.as_table_mut()) - .flat_map(|source| source.iter_mut().map(|(_, dep)| dep)), - ), - _ => deps.extend(table.iter_mut().map(|(_, dep)| dep)), + // What the library builds, not what tests do. + let built = |kind: &Option| kind.as_deref() != Some("dev"); + for dep in node.deps.iter().filter(|d| d.dep_kinds.iter().any(|k| built(&k.kind))) { + queue.push(&dep.pkg); + let Some(resolved) = packages.get(dep.pkg.as_str()) else { + continue; + }; + // Unrenamed, the edge is named by the library's crate name. + let lib = (resolved.targets.iter()).find(|t| t.kind.iter().any(|k| k.contains("lib") || k == "proc-macro")); + let named = (package.dependencies.iter()).find(|d| { + let name = d.rename.as_deref().or(lib.map(|t| t.name.as_str())); + built(&d.kind) && d.name == resolved.name && name.map(|n| n.replace('-', "_")) == Some(dep.name.clone()) + }); + // A path dependency names no source to patch. + let Some(named) = named.and_then(|d| d.source.as_deref()) else { + continue; + }; + // A git package's source adds the commit it resolved to. + let source = resolved.source.as_deref().map(|s| s.split('#').next().unwrap_or(s)); + if source == Some(named) { + continue; + } + let key = patch_key(named)?; + let replacement = match resolved.source.as_deref() { + None => { + let dir = resolved.manifest_path.parent().expect("a manifest path has a parent"); + toml::toml! { path = (dir.display().to_string()) } + } + Some(git) if git.starts_with("git+") => { + let (url, rev) = git["git+".len()..].split_once('#').unwrap_or((git, "")); + let url = url.split('?').next().unwrap_or(url); + // Only a `[replace]` resolves a package to another commit of the source + // the dependency names; cargo refuses a patch from that source. + if url == key { + return Err(format!( + "{} {} is replaced from its own source, which a `[patch]` of the export's library cannot carry", + resolved.name, resolved.version + )); + } + // A repository may hold several versions of the package. + let version = format!("={}", resolved.version); + toml::toml! { git = url rev = rev version = version } + } + Some(other) => { + return Err(format!( + "{} {} is patched in from {other}, which the export's library cannot patch in", + resolved.name, resolved.version + )); + } + }; + let into = patch.entry(key).or_insert_with(|| toml::Table::new().into()); + let into = into.as_table_mut().expect("a patch's source is a table"); + match into.get(&resolved.name) { + Some(toml::Value::Table(existing)) if *existing == replacement => {} + // Two versions of one package patched in from one source. + Some(_) => { + let mut renamed = replacement; + renamed.insert("package".to_string(), resolved.name.clone().into()); + into.insert(format!("{}-{}", resolved.name, resolved.version), renamed.into()); + } + None => { + into.insert(resolved.name.clone(), replacement.into()); + } + } } } - // A dependency's own table: a bare string is a version requirement. - for dep in deps { - if let Some(toml::Value::String(path)) = dep.get_mut("path") { - *path = root.join(path.as_str()).display().to_string(); - } + Ok(patch) +} + +/// The `[patch]` key of a source as `cargo metadata` spells it. +fn patch_key(source: &str) -> Result { + if source == "registry+https://github.com/rust-lang/crates.io-index" || source == "sparse+https://index.crates.io/" + { + return Ok("crates-io".to_string()); + } + if let Some(url) = source.strip_prefix("registry+") { + return Ok(url.to_string()); } - overrides + if source.starts_with("sparse+") { + return Ok(source.to_string()); + } + if let Some(url) = source.strip_prefix("git+") { + return Ok(url.split(['?', '#']).next().unwrap_or(url).to_string()); + } + Err(format!("a patch of {source}, which the export's library cannot patch")) } /// What a cargo subcommand prints for the package, run as the check resolves: from the @@ -302,7 +377,6 @@ impl<'a> Picks<'a> { struct Metadata { packages: Vec, resolve: Resolve, - workspace_root: PathBuf, } #[derive(serde::Deserialize)] @@ -350,6 +424,8 @@ struct Dependency { rename: Option, /// `dev` or `build`, or none for a normal dependency. kind: Option, + /// The source it names, such as `registry+`, or none for a path dependency. + source: Option, } #[derive(serde::Deserialize)] @@ -362,21 +438,6 @@ struct Target { mod tests { use super::*; - #[test] - fn absolutes_override_paths() { - let manifest: toml::Table = "[dependencies]\nx = { path = \"x\" }\n\n\ - [patch.'https://example.com/git']\npath = \"1\"\nreal = { path = \"real\" }\n\n\ - [replace]\n\"a:1.0.0\" = { path = \"a\" }\n" - .parse() - .unwrap(); - let expected: toml::Table = - "[patch.'https://example.com/git']\npath = \"1\"\nreal = { path = \"/ws/real\" }\n\n\ - [replace]\n\"a:1.0.0\" = { path = \"/ws/a\" }\n" - .parse() - .unwrap(); - assert_eq!(overrides(&manifest, Path::new("/ws")), expected); - } - #[test] fn reads_what_picks_a_resolution() { for spelling in [ diff --git a/ffi/src/config.rs b/ffi/src/config.rs index e0ca55008..9c9043db0 100644 --- a/ffi/src/config.rs +++ b/ffi/src/config.rs @@ -116,7 +116,7 @@ pub mod env { pub const CENSUS: &str = "RUST2_FFI_CENSUS"; /// Each export's [`Package`](super::Package), a line each. pub const CRATES: &str = "RUST2_FFI_CRATES"; - /// The configured workspace's `[patch]` and `[replace]` tables, as TOML with each + /// The `[patch]` resolving the configured package as cargo did, as TOML with each /// path absolute. pub const PATCH: &str = "RUST2_FFI_PATCH"; } diff --git a/ffi/src/glue.rs b/ffi/src/glue.rs index 38538152d..bca9009b2 100644 --- a/ffi/src/glue.rs +++ b/ffi/src/glue.rs @@ -47,8 +47,8 @@ pub struct Crate<'a> { pub abi: &'a Abi<'a>, /// The exported packages, the configured one first, each a dependency of the crate. pub exports: &'a [Package], - /// The configured workspace's `[patch]` and `[replace]` tables, which the crate's own - /// workspace resolves the exports with. + /// The `[patch]` table the crate's own workspace resolves the exports with, as the + /// check did. pub patch: &'a str, } @@ -102,6 +102,7 @@ impl Crate<'_> { let mut generator = Gen { abi: self.abi, packages: self.packages(), + dependencies: self.exports.iter().map(|export| dependency(&export.root())).collect(), out: String::new(), }; generator.lib(); @@ -116,6 +117,8 @@ struct Gen<'a> { abi: &'a Abi<'a>, /// The exported packages, for the docs. packages: String, + /// The name the crate depends on each export by. + dependencies: Vec, out: String, } @@ -305,6 +308,12 @@ impl Gen<'_> { self.line("#![allow(dead_code, reason = \"the runtime serves every API\")]\n"); self.line("mod rt;\n"); self.line("use std::ffi::c_void;\n"); + // An export may export nothing and only enable features in the others, as a + // package standing in for a binding crate does, which cargo would call unused. + for dependency in self.dependencies.clone() { + self.line(format!("use {dependency} as _;")); + } + self.line(""); let p = self.abi.prefix.clone(); self.line(format!( diff --git a/ffi/tests/fixtures.rs b/ffi/tests/fixtures.rs index 064e8c365..d79d4b8ab 100644 --- a/ffi/tests/fixtures.rs +++ b/ffi/tests/fixtures.rs @@ -474,41 +474,279 @@ fn lookalike() { .arg(package.join("glue"))); } +/// Writes each `(path, text)` into `dir`. +fn write_all(dir: &Path, files: &[(&str, &str)]) { + for (path, text) in files { + let path = dir.join(path); + std::fs::create_dir_all(path.parent().unwrap()).unwrap(); + std::fs::write(path, text).unwrap(); + } +} + +/// Export the package in `dir` with cargo `args`, then build its glue offline from +/// here, with the lockfile the check resolved. +fn export_and_build(dir: &Path, args: &[&str]) { + let out = dir.join("out"); + let output = Command::new(env!("CARGO_BIN_EXE_rust2-ffi")) + .arg("--config") + .arg(dir.join("ffi.toml")) + .arg("--out") + .arg(&out) + .arg("--") + .args(args) + .env("CARGO_TARGET_DIR", dir.join("build")) + .output() + .unwrap(); + assert!( + output.status.success(), + "the export failed:\n{}", + String::from_utf8_lossy(&output.stderr) + ); + std::fs::copy(dir.join("Cargo.lock"), out.join("Cargo.lock")).unwrap(); + run(cargo() + .args(["build", "--quiet", "--offline", "--manifest-path"]) + .arg(out.join("Cargo.toml")) + .arg("--target-dir") + .arg(dir.join("glue"))); +} + /// Another export patched in for a registry dependency is bound by its resolved package, -/// though the dependency names no path, and the glue builds it patched in too. +/// though the dependency names no path, and the glue builds it patched in too, though +/// the dependency goes by its library's crate name. So is a dependency of no platform's, +/// which cargo resolves all the same. #[test] fn patched() { let package = package("patched"); + write_all( + &package, + &[ + ( + "dep/Cargo.toml", + "[package]\nname = \"rust2-ffi-patched-dep\"\nversion = \"1.0.0\"\nedition = \"2024\"\n\n\ + [lib]\nname = \"rust2_ffi_patched_core\"\n", + ), + ("dep/src/lib.rs", "pub struct Size {\n\tpub width: u32,\n}\n"), + ( + "inactive/Cargo.toml", + "[package]\nname = \"rust2-ffi-patched-inactive\"\nversion = \"1.0.0\"\nedition = \"2024\"\n", + ), + ("inactive/src/lib.rs", ""), + ( + "Cargo.toml", + "[package]\nname = \"patched\"\nversion = \"0.0.0\"\nedition = \"2024\"\n\n\ + [dependencies]\nrust2-ffi-patched-dep = \"1\"\n\n\ + [target.'cfg(any())'.dependencies]\nrust2-ffi-patched-inactive = \"1\"\n\n\ + [patch.crates-io]\nrust2-ffi-patched-dep = { path = \"dep\" }\n\ + rust2-ffi-patched-inactive = { path = \"inactive\" }\n\n\ + [workspace]\nexclude = [\"dep\", \"inactive\"]\n", + ), + ( + "src/lib.rs", + "pub fn width(size: rust2_ffi_patched_core::Size) -> u32 {\n\tsize.width\n}\n", + ), + ("ffi.toml", "package = \"patched\"\n\n[crates.rust2-ffi-patched-dep]\n"), + ], + ); + export_and_build(&package, &["--offline"]); +} + +/// A commit of all of `dir`'s files. +const COMMIT: [&str; 8] = [ + "-c", + "user.name=t", + "-c", + "user.email=t@t", + "commit", + "--quiet", + "-am", + "commit", +]; + +/// The URL of a new git repository in `dir`, whose branch `main` holds `files`. +fn repository(dir: &Path, files: &[(&str, &str)]) -> String { + let _ = std::fs::remove_dir_all(dir); + write_all(dir, files); + for args in [ + &["init", "--quiet", "--initial-branch", "main"][..], + &["add", "."], + &COMMIT, + ] { + run(Command::new("git").args(args).current_dir(dir)); + } + format!("file://{}", dir.display()) +} + +/// A dependency patched in from a git repository that holds two versions of it, the patch +/// picking one by version, is carried with the version it resolved to. +#[test] +fn git_patched() { + let package = package("git_patched"); + let manifest = + |version| format!("[package]\nname = \"rust2-ffi-git-dep\"\nversion = \"{version}\"\nedition = \"2024\"\n"); + let stale = repository( + &package.join("stale"), + &[("Cargo.toml", &manifest("1.0.0")), ("src/lib.rs", "")], + ); + let fresh = repository( + &package.join("fresh"), + &[ + ("one/Cargo.toml", &manifest("1.0.0")), + ("one/src/lib.rs", ""), + ("two/Cargo.toml", &manifest("2.0.0")), + ("two/src/lib.rs", ""), + ], + ); + let text = format!( + "[package]\nname = \"git_patched\"\nversion = \"0.0.0\"\nedition = \"2024\"\n\n\ + [dependencies]\nrust2-ffi-git-dep = {{ git = \"{stale}\" }}\n\n\ + [patch.\"{stale}\"]\nrust2-ffi-git-dep = {{ git = \"{fresh}\", version = \"1\" }}\n\n\ + [workspace]\nexclude = [\"stale\", \"fresh\"]\n" + ); + write_all(&package, &[("Cargo.toml", &text)]); + export_and_build(&package, &[]); +} + +/// Another export the workspace `[replace]`s, by a spec naming no package, is carried as +/// a `[patch]` of it, which resolves alike since a replacement keeps its version. A +/// replacement from the source it replaces is an error, since no patch can carry it. +#[test] +fn replaced() { + let package = package("replaced"); + // A git repository the dependency names, whose default branch lacks the field the + // package reads, named for the package so the spec names it by its URL. + let manifest = "[package]\nname = \"rust2-ffi-replaced-dep\"\nversion = \"1.0.0\"\nedition = \"2024\"\n"; + let git = package.join("rust2-ffi-replaced-dep"); + let url = repository( + &git, + &[ + ("Cargo.toml", manifest), + ("src/lib.rs", "pub struct Size {\n\tpub height: u32,\n}\n"), + ], + ); + run(Command::new("git") + .args(["checkout", "--quiet", "-b", "fixed"]) + .current_dir(&git)); + write_all(&git, &[("src/lib.rs", "pub struct Size {\n\tpub width: u32,\n}\n")]); + run(Command::new("git").args(COMMIT).current_dir(&git)); + let files = |replacement: &str| { + write_all( + &package, + &[ + ("dep/Cargo.toml", manifest), + ("dep/src/lib.rs", "pub struct Size {\n\tpub width: u32,\n}\n"), + ( + "Cargo.toml", + &format!( + "[package]\nname = \"replaced\"\nversion = \"0.0.0\"\nedition = \"2024\"\n\n\ + [dependencies]\nrust2-ffi-replaced-dep = {{ git = \"{url}\", branch = \"main\" }}\n\n\ + [replace]\n\"{url}#1.0.0\" = {replacement}\n\n\ + [workspace]\nexclude = [\"dep\", \"rust2-ffi-replaced-dep\"]\n" + ), + ), + ( + "src/lib.rs", + "pub fn width(size: rust2_ffi_replaced_dep::Size) -> u32 {\n\tsize.width\n}\n", + ), + ( + "ffi.toml", + "package = \"replaced\"\n\n[crates.rust2-ffi-replaced-dep]\n", + ), + ], + ); + }; + files("{ path = \"dep\" }"); + export_and_build(&package, &[]); + // Not an export, which is a path package, but what the package builds with. + files(&format!("{{ git = \"{url}\", branch = \"fixed\" }}")); + write_all( + &package, + &[("ffi.toml", "package = \"replaced\"\nexclude = [\"width\"]\n")], + ); + let output = census(&package.join("ffi.toml"), &[]).output().unwrap(); + assert!(!output.status.success(), "a replacement from its own source passed"); + let stderr = String::from_utf8_lossy(&output.stderr); + assert!( + stderr.contains("rust2-ffi-replaced-dep 1.0.0 is replaced from its own source"), + "{stderr}" + ); +} + +/// Patches in cargo's config, which cargo reads only where the check runs, reach the glue +/// as the check resolved them: an ancestor's file through its `include`, with paths from +/// the directory holding its `.cargo`, outranking the manifest's patch of the same +/// dependency under another spelling of its source, and a `--config` value's `include`, +/// from the package's directory. Both name that source by a registry only the config +/// defines, whose index the environment overrides. +#[test] +fn config_patched() { + let root = scratch().join("config-patched"); let write = |path: &str, text: &str| { - let path = package.join(path); + let path = root.join(path); std::fs::create_dir_all(path.parent().unwrap()).unwrap(); std::fs::write(path, text).unwrap(); }; + let dep = |dir: &str, name: &str, item: &str| { + write( + &format!("{dir}/Cargo.toml"), + &format!("[package]\nname = \"{name}\"\nversion = \"1.0.0\"\nedition = \"2024\"\n"), + ); + write(&format!("{dir}/src/lib.rs"), item); + }; + dep( + "pkg/dep", + "rust2-ffi-config-dep", + "pub struct Size {\n\tpub width: u32,\n}\n", + ); + // What the manifest patches in, which lacks the field the package reads. + dep( + "pkg/stale", + "rust2-ffi-config-dep", + "pub struct Size {\n\tpub height: u32,\n}\n", + ); + dep( + "pkg/cli", + "rust2-ffi-config-cli", + "pub struct Margin {\n\tpub width: u32,\n}\n", + ); + write(".cargo/config.toml", "include = [\"patch.toml\"]\n"); write( - "dep/Cargo.toml", - "[package]\nname = \"rust2-ffi-patched-dep\"\nversion = \"1.0.0\"\nedition = \"2024\"\n", + ".cargo/patch.toml", + "[registries.index]\nindex = \"https://example.com/index\"\n\n\ + [patch.index]\nrust2-ffi-config-dep = { path = \"pkg/dep\" }\n", ); - write("dep/src/lib.rs", "pub struct Size {\n\tpub width: u32,\n}\n"); write( - "Cargo.toml", - "[package]\nname = \"patched\"\nversion = \"0.0.0\"\nedition = \"2024\"\n\n\ - [dependencies]\nrust2-ffi-patched-dep = \"1\"\n\n\ - [patch.crates-io]\nrust2-ffi-patched-dep = { path = \"dep\" }\n\n\ - [workspace]\nexclude = [\"dep\"]\n", + "pkg/.cargo/cli.toml", + "[patch.index]\nrust2-ffi-config-cli = { path = \"cli\" }\n", ); write( - "src/lib.rs", - "pub fn width(size: rust2_ffi_patched_dep::Size) -> u32 {\n\tsize.width\n}\n", + "pkg/Cargo.toml", + "[package]\nname = \"config-patched\"\nversion = \"0.0.0\"\nedition = \"2024\"\n\n\ + [dependencies]\nrust2-ffi-config-cli = \"1\"\nrust2-ffi-config-dep = \"1\"\n\n\ + [patch.'https://github.com/rust-lang/crates.io-index']\nrust2-ffi-config-dep = { path = \"stale\" }\n\n\ + [workspace]\nexclude = [\"cli\", \"dep\", \"stale\"]\n", ); - write("ffi.toml", "package = \"patched\"\n\n[crates.rust2-ffi-patched-dep]\n"); - let out = package.join("out"); + write( + "pkg/src/lib.rs", + "pub fn width(size: rust2_ffi_config_dep::Size, cli: rust2_ffi_config_cli::Margin) -> u32 {\n\ + \tsize.width + cli.width\n}\n", + ); + write( + "pkg/ffi.toml", + "package = \"config-patched\"\n\n[crates.rust2-ffi-config-cli]\n\n[crates.rust2-ffi-config-dep]\n", + ); + let out = root.join("out"); let output = Command::new(env!("CARGO_BIN_EXE_rust2-ffi")) .arg("--config") - .arg(package.join("ffi.toml")) + .arg(root.join("pkg/ffi.toml")) .arg("--out") .arg(&out) - .args(["--", "--offline"]) - .env("CARGO_TARGET_DIR", package.join("build")) + .args(["--", "--offline", "--config", "include = [\".cargo/cli.toml\"]"]) + .env("CARGO_TARGET_DIR", root.join("build")) + // What the check resolves `index` by, outranking its config. + .env( + "CARGO_REGISTRIES_INDEX_INDEX", + "https://github.com/rust-lang/crates.io-index", + ) .output() .unwrap(); assert!( @@ -516,10 +754,10 @@ fn patched() { "the export failed:\n{}", String::from_utf8_lossy(&output.stderr) ); - // The glue's workspace patches the export in as the configured one does. + // Built from here, where none of that config is read. run(cargo() .args(["build", "--quiet", "--offline", "--manifest-path"]) .arg(out.join("Cargo.toml")) .arg("--target-dir") - .arg(package.join("glue"))); + .arg(root.join("glue"))); } diff --git a/quest/m1/ffi-export.md b/quest/m1/ffi-export.md index 4510fdf92..a397baaf9 100644 --- a/quest/m1/ffi-export.md +++ b/quest/m1/ffi-export.md @@ -19,25 +19,13 @@ census refuses and what moq waits on: makes `Path` owned. Once it lands, bump the moq pin: the census then exports `Path::new`, `strip_prefix`, and `Relative::new`, and drops `AsPath` and the `borrow` methods from [the exclude list](/ffi/moq/ffi.toml), refusing only `Path::from_static`'s `'static` borrow. -- **Several crates**: moq-tokio's sessions and the media crates (hang, moq-mux) hold - moq-ffi's remaining API. Export them as moq-pattern and moq-clock already export beside - moq-net, each under `[crates.]` in [the config](/ffi/moq/ffi.toml). The checked - package must build with every export, so this needs moq-ffi's remainder, or a crate - standing in for it, as that package. Decided with the maintainer: - - ✅ Each crate is its own export with its own census, and an export names another's - types across crates, not names at a re-export's path. - - ✅ One rustc session collects every export from metadata: one IR, one glue crate, one - library. - - ✅ One prefix per library, with names from each crate's root and clashes checked across - exports. - - ✅ One header, `include/.h`. - - ✅ One `ffi.toml`, with a `[crates.]` table per other export, and - `--census ` writing `.md` for each. - - Landed in [#76](https://github.com/kixelated/rust2/pull/76). Next, decided with the - maintainer on 2026-10-26: the glue also carries the `[patch]` tables cargo reads - from `.cargo/config.toml` (config has no `[replace]`), with cargo's precedence - between config and manifest and paths relative to the config file. moq-clock is - merging into kio, so its export moves with it and its C names wait until then. +- **Several crates**: moq-net, moq-pattern, moq-clock, moq-tokio, hang, and moq-mux export + into one library through an empty package standing in for moq-ffi's remainder, which + `just ffi standin` writes; moq-ffi takes its place once it shrinks to that remainder. + Left: + - moq-clock's C names (`moq_now`, `moq_origin`) wait for its merge into kio. + - A field and a method of one name, such as moq-tokio's `Backoff::initial`, claim one C + name that `rename` cannot split, so [the config](/ffi/moq/ffi.toml) excludes both. - **Driving**: sessions and origins run a `Driver` polled with a time and a `kio::Waiter`. Decide between exporting that poll, a generated thread that drives it, or moq-tokio's runtime helpers.