Skip to content

fix: regenerate deltachat.pc if env changed - #8752

Open
d2weber wants to merge 1 commit into
mainfrom
d2weber/pc-on-env-changed
Open

d2weber wants to merge 1 commit into
mainfrom
d2weber/pc-on-env-changed

Conversation

@d2weber

@d2weber d2weber commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Paths in deltachat.pc are passed via env variables to build.rs. With this fix, the pc will be regenerated if these env variables change.

This came up when building via CMake: the paths depend on CMAKE_INSTALL_PREFIX, if the CMAKE_INSTALL_PREFIX changes during a reconfigure, deltachat.pc should have the corresponding paths adjusted.

Paths in deltachat.pc are passed via env variables to build.rs.
With this fix, the pc will be regenerated if these env variables
change.

This came up when building via CMake: the paths depend on
CMAKE_INSTALL_PREFIX, if the CMAKE_INSTALL_PREFIX changes during a
reconfigure, deltachat.pc should have the corresponding paths adjusted.
Comment thread deltachat-ffi/build.rs
prefix = env::var("PREFIX").unwrap_or_else(|_| "/usr/local".to_string()),
libdir = env::var("LIBDIR").unwrap_or_else(|_| "/usr/local/lib".to_string()),
includedir = env::var("INCLUDEDIR").unwrap_or_else(|_| "/usr/local/include".to_string()),
prefix = option_env!("PREFIX").unwrap_or_else(|| "/usr/local"),

@link2xt link2xt Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disadvantage of this is that this builds the value itself into the build script executable (as a static str), so the build script will have to be rebuilt every time. It looks like option_env! is meant for the source code of the programs rather than build scripts.

A better way is probably to add println!("cargo:rerun-if-changed=PREFIX") to the build script: https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-env-changed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before I tried it and to me it looked like the build script only got re executed when the env variable actually changed (which is what we want)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the build script is also rebuilt because the value is built into the binary produced from build.rs, which is unnecessary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal because compiling build.rs is very cheap (compared to compiling the library).

This branch has not been deployed

No deployments
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.

2 participants