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

Automatically Provide Cargo-related Environment Variables as WiX Variables #118

Open
volks73 opened this issue Nov 8, 2020 · 5 comments
Assignees

Comments

@volks73
Copy link
Owner

volks73 commented Nov 8, 2020

As discussed and finally realized by me in #113, the user may want access to various build-related variables within his or her own custom WXS file to create an installer depending on the build environment. For example, determine if the -gnu or -msvc toolchains are used. The Cargo environment variables list should be reviewed and determine which should be included automatically and which can be accessed from a cargo subcommand.

  1. I am not sure if any of these variables are accessible from a cargo subcommand and/or the best method of obtaining them.
  2. A consistent naming convention for the variable names needs to be established. Rust constant style (CARGO_CONSTANT) or Wix variable style (CargoConstant)? Prefix with Cargo or CargoWix?
@roblabla
Copy link
Contributor

roblabla commented Nov 10, 2020

So there isn't any easy way to tell cargo "give me all the variables" (well, I can think of a few hacks, but nothing clean). Here are those we know of today, if they are useful, and if we can get them or not:

  • CARGO: Path to cargo binary. Unneeded.
  • CARGO_MANIFEST_DIR: cargo-metadata can provide it.
  • CARGO_MANIFEST_LINKS: Unnecessary I believe. cargo-metadata can provide it.
  • CARGO_FEATURE_<name>: This one's a bit complicated, when combined with cargo wix --no-build, we have no way of knowing which features were used for the build that I know of (though maybe there's some file in the target directory that could tell us? Need to dig.). I do see how it could be useful though.
  • CARGO_CFG_<cfg>: Can be acquired with cargo --print cfg. See Refactor wix_arch() implementation #126.
  • OUT_DIR: Unnecessary, this is build-script specific.
  • TARGET: We already pass it. Target triple name.
  • HOST: This one's interesting. We technically have it through get_host_triple, but I don't know how useful it would be within a WXS.
  • NUM_JOBS: Unneeded.
  • OPT_LEVEL, DEBUG: cargo_metadata::Artifact can give it, but that interacts poorly with --no-build.
  • PROFILE: We already have it.
  • DEP_<name>_<key>: Unneeded.
  • RUSTC, RUSTDOC, RUSTC_LINKER: Path to binaries. Unneeded..

@volks73
Copy link
Owner Author

volks73 commented Nov 21, 2020

Just a minor correction in case someone finds this issue. It is the rustc --print cfg, not cargo --print cfg. Cargo does not have a --print option.

@volks73
Copy link
Owner Author

volks73 commented Nov 21, 2020

In summary, the only Cargo variable of interest is the CARGO_FEATURE_<name> variables, but this will take some work to investigation and work and the CARGO_CFG_<cfg> variable, which is available with the rustc --print cfg/rustc-cfg crate. The rest of the variables are either not needed or already provided via other mechanisms.

Since the CARGO_CFG_<cfg> variables are obtained from the rustc --print cfg output, I am going to create another issue (#132) to track and discuss adding rustc --print cfg output as WiX variables and keep this one focused on the Cargo-related variables (now just implementing the CARGO_FEATURE_<name> variables).

@plule
Copy link

plule commented Oct 28, 2023

Hello,

OUT_DIR: Unnecessary, this is build-script specific.

I think this one would actually be very useful for intermediary files generated by build.rs. In my case I have an .svg icon that is converted into a .ico as part of the build process. The recommendation for build scripts is to only produce files in OUT_DIR, so using it in wix with a <Icon Id='icon.exe' SourceFile='$(var.CargoOutDir)\icon.ico'/> would make a lot of sense.

@roblabla
Copy link
Contributor

The problem is, the OUT_DIR is different for each artifact (ergo each binary of a crate has its own OUT_DIR), so if we do this, at the very least it'd be something like CargoOutDirBin<BinName>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants