FFFF
Skip to content

Forced recompile passes --cfg to cargo rustc without --; hyphenated crates always trigger it #754

Description

@nymph-ai

Description

Rustler's forced-recompile path passes --cfg directly to cargo rustc without Cargo's -- separator. Cargo rejects the argument, so any build that reaches this recovery path fails even when the initial crate compilation succeeded.

This is present in rustler 0.38.0 and still present on current master in rustler_mix/lib/rustler/compiler.ex:

args ++ ["--cfg", "build_#{System.system_time(:millisecond)}"]

Reproduction

Configure a NIF crate whose package name contains a hyphen, for example potamid-nif.

  1. Cargo builds libpotamid_nif.so and Rustler copies it as potamid_nif.so.
  2. expected_files/1 derives the expected name from config.crate verbatim, so it looks for potamid-nif.so.
  3. The mismatch triggers the forced recompile.
  4. The retry invokes the equivalent of:
cargo rustc ... --cfg build_...

and fails:

error: unexpected argument '--cfg' found
tip: to pass '--cfg' as a value, use '-- --cfg'

The first build completed and copied the artifact; only the recovery build fails.

Expected behavior

  • Rust compiler flags on the forced-recompile path are passed after Cargo's -- separator.
  • Expected library filenames account for Cargo's hyphen-to-underscore normalization, so a valid hyphenated crate does not spuriously enter recovery.

Workaround

Name the crate with an underscore so config.crate matches Cargo's artifact name and the broken retry is not reached.

Local tracking and full output: https://github.com/nymph-ai/nymphai/issues/1140

Environment

  • rustler 0.38.0
  • Linux x86_64
  • current Cargo (error reproduced through cargo rustc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0