Skip to content

Conversation

@cwshugg
Copy link

@cwshugg cwshugg commented Feb 11, 2025

This PR implements an environment variable that can be used to toggle the usage of the --offline option when trybuild invokes cargo. The default behavior has not been modified; --offline is still used by default, but there is now the option to disable the usage --offline by setting this environment variable:

TRYBUILD_NO_OFFLINE_MODE=1

Always invoking cargo with --offline was discussed in #50 and implemented in this commit). As discussed in #296, in some situations, trybuild is unable to access certain resources outside of the target directory. I've noticed a similar problem when setting CARGO_TARGET_DIR to somewhere else on the system (I have a constraint that requires this), and found that removing --offline allows dependencies to be pulled when trybuild sets the target directory here in the code.

I figured, for this reason, and for others in the future, it may be handy to have the option to choose whether or not --offline is used by trybuild. Would love to hear any feedback and make suggested changes - thanks!

@cwshugg cwshugg marked this pull request as ready for review February 11, 2025 18:36
@cwshugg
Copy link
Author

cwshugg commented Feb 21, 2025

Hi @dtolnay - could I request a review for this PR if you have the time? Thanks!

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I would prefer not to add this to this crate. But there is an opportunity for someone to make a more fully featured compile error testing library that provides this.

I would accept some other fix that better supports different target directory arrangements as long as it works automatically.

@dtolnay dtolnay closed this Feb 21, 2025
@cwshugg
Copy link
Author

cwshugg commented Feb 24, 2025

Hey @dtolnay - thanks for the review, and for explaining. A few ideas for automatic solutions - if you would accept either of these, I'd be happy to implement one:

  • Disable --offline when it's detected that CARGO_TARGET_DIR is outside of the cargo crate under test
  • Do not override CARGO_TARGET_DIR when invoking cargo if it has already been set by the user

Could I point you to #296? Others seem to be having similar issues, moreso related to file paths specified within their Rust code. The root of their issues, and the issue I have been seeing, both seem to be at the fact that CARGO_TARGET_DIR is overridden. Is it an absolute must that CARGO_TARGET_DIR be set to CURRENT_TARGET_DIRECTORY/tests/trybuild?

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