Skip to content

build: Make build.rs candle-kernels compatible with Nix and sandboxed builds#3059

Merged
greenrazer merged 3 commits into
huggingface:mainfrom
joeldsouzax:fix-bindgen-cuda-outdir
Aug 28, 2025
Merged

build: Make build.rs candle-kernels compatible with Nix and sandboxed builds#3059
greenrazer merged 3 commits into
huggingface:mainfrom
joeldsouzax:fix-bindgen-cuda-outdir

Conversation

@joeldsouzax

Copy link
Copy Markdown
Contributor

This PR fixes an issue where the build.rs script writes generated files directly to the src/ directory. This practice violates Cargo's guidelines and causes build failures in sandboxed environments like Nix, where the source directory is read-only.

Changes:

build.rs: The script is updated to write ptx.rs to the Cargo-designated $OUT_DIR instead of src/.

src/lib.rs: The ptx module is now loaded using the include!(concat!(env!("OUT_DIR"), "/ptx.rs")); macro, which is the standard pattern for including code generated by a build script.

This makes the crate compliant with Cargo best practices and significantly improves its compatibility with reproducible build systems.

@gmacon gmacon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. Thanks!

Comment thread candle-kernels/build.rs

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This file is missing some imports:

use std::env;
use std::path::PathBuf;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is soo stupid of me :/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Happens to me more times than I dare to admit :)

@ivarflakstad ivarflakstad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this 👍

@greenrazer greenrazer merged commit bf82629 into huggingface:main Aug 28, 2025
9 checks passed
@greenrazer

Copy link
Copy Markdown
Contributor

Thanks!

john-sharratt pushed a commit to john-sharratt/candle that referenced this pull request May 7, 2026
… builds (huggingface#3059)

* Use OUT_DIR for generated PTX bindings

* fix: fixed the out_dir cargo problem in examples

* fix: added imports in build.rs
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.

5 participants