serde-rs / serde

Serialization framework for Rust
https://serde.rs/
Apache License 2.0
8.81k stars 747 forks source link

Serde fails to build with debug = false profile inside workspace crate #2718

Closed solarretrace closed 1 month ago

solarretrace commented 3 months ago

One of my older crates started to fail to compile when updating serde.

MacOS version 11.7.10 rustc 1.77.0 (aedd173a2 2024-03-17)

cargo build --release
   Compiling proc-macro2 v1.0.79
   Compiling unicode-ident v1.0.12
   Compiling autocfg v1.1.0
   Compiling serde v1.0.197
error: failed to run custom build command for `proc-macro2 v1.0.79`

Caused by:
  process didn't exit successfully: `/test-rs/target/release/build/proc-macro2-4f7bdfadadf2577d/build-script-build` (signal: 9, SIGKILL: kill)
warning: build failed, waiting for other jobs to finish...
error: failed to run custom build command for `serde v1.0.197`

Caused by:
  process didn't exit successfully: `/test-rs/target/release/build/serde-dae687d13072669a/build-script-build` (signal: 9, SIGKILL: kill)

This only recreates when I build with debug = false in the build profile (--release mode,) AND if I'm building serde for a package within a workspace.

[workspace.dependencies]
serde = { version = "1.0", features = ["derive", "rc"] }

I occasionally get the following error instead, though I don't yet know what exactly causes the different error message. It seems to have something to do with setting debug = true in the release profile and debug = false in the dev profile.

 cargo check
    Checking serde v1.0.197
error: dlopen(/test-rs/target/debug/deps/libserde_derive-2d618114b1598331.dylib, 5): REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 1 which is not a writable segment (__TEXT) in /test-rs/target/debug/deps/libserde_derive-2d618114b1598331.dylib
   --> /Users/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/lib.rs:325:1
    |
325 | extern crate serde_derive;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `serde` (lib) due to 1 previous error

Workaround right now is to use debug = true always (though I'd rather have it off if I'm not using it.)

dtolnay commented 1 month ago

I'm not seeing anything in those errors that would suggest this is an issue with serde, so I don't think I can help you debug whatever is going on. I would recommend trying any of the resources listed in https://www.rust-lang.org/community.