Skip to content

Ship vendored sonic-rs in the Hex package - #49

Merged
lpgauth merged 1 commit into
mainfrom
fix-source-build-packaging
Aug 5, 2026
Merged

Ship vendored sonic-rs in the Hex package#49
lpgauth merged 1 commit into
mainfrom
fix-source-build-packaging

Conversation

@lpgauth

@lpgauth lpgauth commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Summary

The published Hex package cannot be built from source. The root Cargo.toml — which is published — redirects the sonic-rs dependency to our vendored, patched copy:

[patch.crates-io]
sonic-rs = { path = "native/sonic-rs" }

but native/sonic-rs was never in the files: list, so Cargo resolves that patch to a path the package doesn't contain:

error: failed to load source for dependency `sonic-rs`
Caused by: Unable to update .../native/sonic-rs

Precompiled NIFs mask this for the eight targets the release workflow builds, so it only bites when RustlerPrecompiled falls back to compiling from source — musl/Alpine, Windows, any NIF version other than 2.15, or an explicit force_build. Those users can't install Torque at all.

This ships the crate's src, Cargo.toml, and LICENSE (the last one also being the right thing to do for vendored third-party code).

Verified by unpacking the built tarball and compiling it standalone:

$ mix hex.build --unpack -o /tmp/pkg2
$ cd /tmp/pkg2 && cargo build --release -p torque_nif
   Compiling sonic-rs v0.3.17 (/tmp/pkg2/native/sonic-rs)
   Compiling torque_nif v0.2.6 (/tmp/pkg2/native/torque_nif)
    Finished `release` profile [optimized] target(s) in 16.29s

Before this change the same command fails at cargo metadata with exit 101.

Tarball grows from ~41 KB to roughly 240 KB.

Note: this defect predates v0.2.6 — v0.2.5 and earlier have it too. v0.2.6 is tagged and on GitHub Releases but was never published to Hex, so no released package needs correcting.

The root Cargo.toml redirects the sonic-rs dependency to the vendored
copy via `[patch.crates-io]`, and that Cargo.toml is published, but
native/sonic-rs was never in the `files:` list. Cargo then resolves the
patch to a path that does not exist in the package:

    error: failed to load source for dependency `sonic-rs`
    Caused by: Unable to update .../native/sonic-rs

Precompiled NIFs hide this for the eight targets the release workflow
builds, so it only surfaces when RustlerPrecompiled falls back to
compiling from source — musl/Alpine, Windows, and any NIF version other
than 2.15 — where the dependency cannot be installed at all.

Ship the crate's src, Cargo.toml, and LICENSE. Verified by unpacking the
built tarball and running `cargo build --release -p torque_nif` in it,
which now compiles sonic-rs from the package's own copy. Adds roughly
200 KB to a 41 KB tarball.
@lpgauth
lpgauth merged commit 0563af1 into main Aug 5, 2026
4 checks passed
@lpgauth

lpgauth commented Aug 5, 2026

Copy link
Copy Markdown
Owner Author

@gilbertwong96 this is part of the 0.2.7 release which is now on hex.pm. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant