Conditional dependencies being built on wrong OS

I'm having an issue with conditional dependencies for a development dependency.

In my Cargo.toml I have:

[target.'cfg(target_os = "linux")'.dev-dependencies]
some_local_crate = { path = "crate_name"} 

On Travis CI the build script is:

script:
  - cargo test --all-features

And runs on Linux, OSX and Windows. The problem that I'm having is that the crate that is configured to only be included if on Linux is being built regardless of the operating system and this causes the build to fail due to the build.rs doing things that only succeed on Linux.

Short of adding a check in the build.rs for the correct OS, I'm not sure how to resolve this? Have I configured the dependency include incorrectly or is it normal for the build.rs to be executed regardless of whether the crate is included?

Are you sure this crate is not being pulled into your dependency graph some other way? For example, are these crates part of a common workspace and are you running cargo test in the workspace?

It's used in two places, in their own modules and behind #[cfg(all(test, target_os = "linux"))]. I can't see how it's being pulled in really. Yes, the test is being run from the root of the workspace.