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

feat!: add target flag #6

Closed
wants to merge 3 commits into from
Closed

feat!: add target flag #6

wants to merge 3 commits into from

Conversation

mainrs
Copy link

@mainrs mainrs commented Sep 15, 2020

This commit adds support for specifying the target triple that blackjack
uses when generating the Bazel rules.

BREAKING CHANGE: The -t,--target argument is mandatory. Existing
tooling fails to run successfully due to it missing. To achieve the same
behavior as in v0.1.0, the target value should be set to
x86_64-unknown-linux-gnu.

Closes #5

This commit adds support for specifying the target triple that blackjack
uses when generating the Bazel rules.

BREAKING CHANGE: The `-t,--target` argument is mandatory. Existing
tooling fails to run successfully due to it missing. To achieve the same
behavior as in v0.1.0, the target value should be set to
`x86_64-unknown-linux-gnu`.

Closes #5
@mainrs
Copy link
Author

mainrs commented Sep 15, 2020

Superseeds #3

Sven Lechner added 2 commits September 16, 2020 01:36
`pico-args` was missing as a dependency. Thus, the crate did compile
locally using cargo but failed with bazel.
Copy link
Owner

@wildarch wildarch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together, Sven!

I think this is good to go once we have a test to make sure the target flag is working as intended.

@@ -7,6 +7,11 @@ use std::path::{Path, PathBuf};
const CARGO_TOML_RUNFILES_PATH: &str = "Cargo.toml";
const CARGO_RUNFILES_PATH: &str = "external/blackjack_cargo/cargo";

struct Args {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change we'll have exactly one allowed flag, and it is also a required one. I think it might be simpler to just use std::env::args for now, we can add an argument parser if the flag situation becomes more complicated in future.

bazel run //:main
popd

pushd tests/workspace
echo | bazel run //:blackjack
echo | bazel run //:blackjack -- --target="$target"
bazel run //crate1
bazel run //crate2
popd
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to test that the --target flag actually makes a difference when generating code. Adding support for Mac and Windows in CI might be a little complicated, but perhaps a simpler approach would be to add a test workspace that compiles on both linux and wasm, but generates a different cargo_dependencies.bzl file for both targets. You could use the time crate as in example, it depends on the stdweb crate only when the target arch is set to wasm32.

Wasm is quite well supported by rules_rust, see https://bazelbuild.github.io/rules_rust/#webassembly. This should run inside the standard ubuntu CI runner.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, just going with Linux, Mac OS and Windows seems pretty easy to do in CI (#8 for reference), so maybe just use that for the tests?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple crate to test with might be: https://docs.rs/os_info/3.0.0/os_info/index.html

@@ -48,7 +48,7 @@ load("@blackjack//:blackjack.bzl", "blackjack")
blackjack(name = "blackjack")
```

Now run `bazel run //:blackjack`. You'll find a newly created `cargo_dependencies.bzl` file next to your `Cargo.toml`.
Now run `bazel run //:blackjack -- --target <triple>`. The `<triple>` argument value is a Rust target triple. You'll find a newly created `cargo_dependencies.bzl` file next to your `Cargo.toml`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe: 'The <triple> argument value is the Rust target triple the dependencies will be built for'

@@ -103,6 +103,3 @@ prefix = "blackjack_crates_io"
```

Now instead of `@crates_io_serde//:serde`, use `blackjack_crates_io_serde//:serde`.

# Things that don't work yet (but would gladly accept a PR for)
* Support for Windows and Mac. For the moment everything assumes your host and target is `x86_64-unknown-linux-gnu`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should leave a note here saying that Mac and Windows support is supported, but untested.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@mainrs mainrs Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had a lot of time lately for programming-related projects :( Would be nice if @wildarch could review https://github.com/SirWindfield/blackjack/pull/1 and see if it is more inline with the changes that he requested 😄

Notable changes as far as I can see:

  • cargo is downloaded depending on the type of platform it runs. All tier 1 platforms are supported (Linux, macOS, Windows).
  • The path to the Cargo.toml file is now configurable. Looks like you don't have to cd into folders now and can invoke the commands from any level (?)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just reviewed the PR, looks great! 😄

@wildarch wildarch mentioned this pull request Oct 20, 2020
@wildarch
Copy link
Owner

I'm going to close this PR now that #9 makes it obsolete.

Thanks for all your efforts @sirwindfield! This was very helpful in putting #9 together 😄

@wildarch wildarch closed this Oct 22, 2020
@mainrs
Copy link
Author

mainrs commented Oct 22, 2020

No problem! Glad that it worked out in the end! I might have some time for the Windows part :)

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

Successfully merging this pull request may close these issues.

Add Windows support
3 participants