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

Rust build.rs build scripts #11

Closed
davidzchen opened this issue Jun 9, 2016 · 3 comments
Closed

Rust build.rs build scripts #11

davidzchen opened this issue Jun 9, 2016 · 3 comments

Comments

@davidzchen
Copy link
Member

davidzchen commented Jun 9, 2016

Many Rust crates have a build.rs build script that is used for arbitrary build tasks before anything else in the crate is built. We should have equivalents for the common use cases that Rust build scripts are used for.

From the Cargo documentation, some of the tasks that can be handled by build.rs include:

  • Building a bundled C library.
  • Finding a C library on the host system.
    • This can be done with Skylark repository rules, though the rules for finding specific libraries still need to be written.
  • Generating a Rust module from a specification.
    • The best way to do this could be just building build.rs as a rust_binary then having something like a genrule target that runs the binary and have the expected output file(s) be inputs to the rust_binary or rust_library target that includes the generated file(s).
    • The key is to make this easy to use for users.
  • Performing any platform-specific configuration needed for the crate.
    • I think this can also be done using Skylark repository rules.
@davidzchen
Copy link
Member Author

Interim proposal: build build.rs as a rust_binary and then run it in a genrule without sandboxing with full access to the local system. This isn't ideal and there are cases this would not support (since build.rs can perform any arbitrary actions), but this may be a stopgap solution for common cases as better solutions for interfacing with large build systems are being discussed in rust-lang/rust-roadmap-2017#12.

@acmcarther
Copy link
Collaborator

I can add a little bit to this. Two findings from my exploration:

  1. build.rs files emit lots of kinds of cargo::stuff that impacts dependencies. That stuff will need to be propagated in the form of flags and out_dir files. Details here.
  2. Invocation of a build.rs will probably require the whole build to be un-hermetic. This is because many of the typical outputs in (1) are paths to system dependencies, which will become unavailable, and especially unlinkable, in subsequent rules. You can imagine building openssl with cargo, and then trying to link that and finding that gcc cant find -l crypto and -l ssl.

@damienmg
Copy link
Collaborator

This is long done.

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