Target-specific features

I've encountered a problem where:

  • rusqlite will only build on macOS if the bundled features is not used
  • rusqlite will only build on Windows if the bundled feature is used

This isn't actually a problem per se; I just need to be able to express this in Cargo.toml, but I'm having some trouble doing that. I tried:

[target.'cfg(windows)'.depedencies]
rusqlite = { version = "0.3.1", features = ["bundled"] }

[target.'cfg(not(windows))'.depedencies]
rusqlite = { version = "0.3.1"  }

But it doesn't appear to be picking the dependencies up at all. (The rusqlite namespace doesn't exist in the code at all). I have a [dependencies] section as well for the common dependencies, in case that matters.


Update:
Per https://github.com/rust-lang/cargo/issues/1197 it looks like per-target features is not supported, unless one uses nightly. Assuming that we're not able to do that -- any other tips for how one would accomplish this? I realize that there's the option to generate the Cargo.toml file from our build script, but that's the kind of hackery I was trying to get away from when choosing Rust for this particular project.

If that's an actual copy-and-paste then it's no wonder that Cargo is not honoring your misspelled "depedencies" as "dependencies". (Note the missing "n".)

2 Likes

It seems I Solved too soon. On macOS it's enabling the bundled feature, despite Cargo.toml only enabling it for windows. To test out the theory that it's using the incorrect one I removed the features = ["bundled"] from the windows section, and then the macOS version built.

Running rustc --print=cfg lists unix, but not windows (as expected).

If I comment these special entries out and add rusqlite to the regular [dependencies] section (without the bundled feature) then it works correctly on macOS.

I also tried to use unix in place of not(windows) but the results are the same.

Hmm.. https://github.com/rust-lang/cargo/issues/1197 :expressionless:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.