Can't access resources outside of the target folder
I have a proc-macro, which loads a file from a given location to generate code. I call it this way:
#[generate_api("tests/good_source_file/mod.rs")]
impl Lifecycle for LifecycleImpl {
Using try build the given file can't be found, because "cwd" and "CARGO_TARGET_DIR" are redirected to $DIR/target/tests/trybuild.
Is there anyway I can change that? I don't want to hardcode a full path - the macro assumes the file's location is relative to the project's root directory.
Needless to say, outside of trybuild::TestCases::new().pass("tests/ui_tests.rs"); the file loading works.
Seconding this, I need a resource adjacent to my test. I ended up using ../../../../<path/from/workspace> to access this, but this is probably not stable and is a bit gross.
Hi, I am running into this issue as well. I have an overarching Rust workspace with several sub-projects that all share the same target directory. Within one of these sub-projects are a few trybuild tests that build fine when the target directory is placed in the default location (within the workspace, i.e. ${workspace}/target).
However, I have noticed that when overriding the target directory by setting CARGO_TARGET_DIR to somewhere else (i.e. /somewhere/outside/of/my/workspace) (I have a constraint that requires me to do this), the trybuild tests fail to compile, throwing a no matching package named PACKAGE_NAME found` for certain dependencies.
I know these "missing" dependencies are present in CARGO_TARGET_DIR, but because trybuild modifies the target directory path at this point in the code, it seems unable to find them.
One workaround I've found for this is removing the cargo --offline argument (added in this PR), but that causes cargo to re-download and re-build them in the new trybuild-based cargo target directory.
@dtolnay do you know of an existing workaround to this issue that would still allow trybuild to use the dependencies outside of the trybuild target directory? If not, I may work on submitting a PR that allows the --offline argument to be enabled or disabled in trybuild.