Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker args are silently ignored by cargo test #2221

Closed
sgrif opened this issue Dec 17, 2015 · 1 comment
Closed

Linker args are silently ignored by cargo test #2221

sgrif opened this issue Dec 17, 2015 · 1 comment

Comments

@sgrif
Copy link
Contributor

sgrif commented Dec 17, 2015

I've been attempting to run Diesel's test suite on Windows, and can't seem to find a way to link a C library. Specifically what I want to be able to do is cargo test -- -LC:\PostgreSQL\lib, but that argument is silently ignored, as is cargo test -- -C link-args="C:\PostgreSQL\lib". cargo rustc -- -LC:\PostgreSQL\lib works fine (though isn't helpful), but cargo rustc --test -- -LC:\PostgreSQL\lib complains that it doesn't know what -L is, and cargo rustc -- --test -LC:\PostgreSQL\lib doesn't include dev-dependencies.

As such, there appears to be no way to test a crate with cargo on Windows if the crate has C libraries that need to be linked, as there doesn't appear to be an environment variable that can be set either.

@alexcrichton
Copy link
Member

Ah, I think that the crux of this issue is a dupe of #2120, so I'm going to close in favor of that, but there's a few other things in play here:

  • First, to link a C library, it's generally recommended to use a build script which can do any form of dynamic detection of the OS, runtime, etc. This build script is then generally shipped in the form of a library which is then reusable by everyone!
  • cargo test -- -LC:\PostgreSQL\lib - this command is actually saying to pass the -L argument to the test binary which is generated (e.g. the arguments after -- are just passed through). It may be the case that our test binaries just ignore unknown flags (like -L)
  • cargo test -- -C link-args="C:\PostgreSQL\lib - as the previous one, this is just passing an argument to the test binary, no the compiler itself.
  • cargo rustc -- -LC:\PostgreSQL\lib - this actually will pass the argument to the compiler, but as you've found it wasn't building your test so not too useful.
  • cargo rustc --test -- -LC:\PostgreSQL\lib - this is actually an interesting one! So when you pass --test to the cargo rustc command (not the underlying rustc), then you're selecting which test to compile. So what this is actually doing is compiling the test named -- (the first thing after the --test argument). The -L flag is then being interpreted as an argument to cargo rustc itself, which is an unknown flag (hence the error)
  • cargo rustc -- --test -LC:\PostgreSQL\lib - aha, and now we run into build test binary with cargo rustc #2120! This should definitely work, but that issue means there's no way for cargo rustc to include dev-dependencies right now unfortunately.

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

No branches or pull requests

2 participants