Skip to content

Conversation

keiichiw
Copy link
Contributor

The can_compile function in build.rs previously invoked rustc with -o -, which causes rustc to attempt to create a temporary metadata directory in the current working directory.

When building this in another build system such as Portage, this happens in a sandbox where the current working directory is not writeable, resulting in a sandbox access violation.

This change modifies the can_compile function to use a temporary directory for the output file. This forces rustc to create the temporary file in a writeable location, avoiding the sandbox issue.

The can_compile function in build.rs previously invoked rustc with
-o -, which causes rustc to attempt to create a temporary metadata
directory in the current working directory.

When building with Portage for ChromeOS, this happens in a sandbox where
the current working directory is not writeable, resulting in a sandbox
access violation.

This change modifies the can_compile function to use a temporary
directory for the output file. This forces rustc to create the temporary
file in a writeable location, avoiding the sandbox issue.
@sunfishcode sunfishcode merged commit fae4d47 into bytecodealliance:main Aug 22, 2025
49 of 51 checks passed
@sunfishcode
Copy link
Member

Thanks!

@keiichiw keiichiw deleted the build-rs-tmpdir branch August 22, 2025 21:12
@sunfishcode
Copy link
Member

This is now released in rustix 1.1.1.

@d-e-s-o
Copy link

d-e-s-o commented Sep 18, 2025

This is now released in rustix 1.1.1.

...and it has been leaking a random file into my /tmp directory ever since. Can we please not do that...? I don't know how many crates I compile on a given day, but it's probably easily in the 100+ range. If everyone leaked random compilation artifacts like that I'd not be able to find jack in there anymore. We really ought to do better than that.

(kudos for at least giving me a chance to understand where it's coming from by encoding the source in the file name, though)

@keiichiw
Copy link
Contributor Author

Thanks for the report. I'll fix it and send a separate PR next week.

keiichiw added a commit to keiichiw/rustix that referenced this pull request Sep 26, 2025
The `can_compile` utility writes its temporary output file to the
system's global temporary directory. This can clutter the host system
with build artifacts.

By using Cargo's `OUT_DIR`, the temporary file is written to a
directory specific to the build, ensuring that build artifacts are
contained within the project's build output and do not mess up the
host system.

Follow-up to bytecodealliance#1497.
@keiichiw
Copy link
Contributor Author

FYI: #1526 is the follow-up PR

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.

3 participants