Skip to content

Panic in prettyplease when building libsqlite3-sys with -Zminimal-versions due to C-string literals #1716

Description

@abonander

Problem

We're seeing failures in our -Zminimal-versions check when trying to upgrade to libsqlite-sys = "0.34.0" (using bindgen = "0.72"): https://github.com/launchbadge/sqlx/actions/runs/16083515240/job/45391511117?pr=3922

error: failed to run custom build command for `libsqlite3-sys v0.34.0`

Caused by:
  process didn't exit successfully: `/home/runner/work/sqlx/sqlx/target/debug/build/libsqlite3-sys-8d75a6a785f86c45/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=LIBSQLITE3_SYS_USE_PKG_CONFIG
  cargo:rerun-if-env-changed=LIBSQLITE3_SYS_BUNDLING

  --- stderr

  thread 'main' panicked at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/prettyplease-0.2.7/src/lit.rs:17:18:
  not implemented: unknown Lit

This suggests that prettyplease = "0.2.7" is too old for whatever syntax bindgen is trying to generate here.

I edited the unimplemented!() at that line in prettyplease to actually print the literal, and it's a C-string literal:

Lit::CStr { token: c"3.49.2" }

After doing some digging, I've figured out that it's actually an issue with the bindgen configuration because generate_cstr is unconditionally set to true here:

.generate_cstr(true)

Solutions

  1. prettyplease 0.2.20 is already an optional dependency, so add it to the features enabled by buildtime-bindgen.
  2. Don't unconditionally pretty-print the generated code, and make it an optional feature or environment flag instead. This would likely speed up build times a bit, and 99% of the time no one is looking anyway. I presume this is mostly for debugging and making the source look nice when rendered by docs.rs.

I'm happy to submit a patch for either option, I just need a decision made.

Workaround

Users can force prettyplease to a higher minimum version by adding it to their own [build-dependencies] section, as Cargo should unify it:

[build-dependencies]
# force `prettyplease` to the minimum version that supports C-string literals for `libsqlite3-sys 0.34.0`
prettyplease = "0.2.18"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions