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

Adding basic windows support #329

Merged
merged 28 commits into from
Jul 1, 2020
Merged

Conversation

jelmansouri
Copy link
Contributor

Adding binary extension support to the rust_binary rule, this allows us to build on windows.

@jelmansouri
Copy link
Contributor Author

I had the change for more than a month, in the meantime this got added:
https://github.com/bazelbuild/rules_rust/pull/322/files
I'm not sure if it breaks my original change

Copy link
Collaborator

@damienmg damienmg left a comment

Choose a reason for hiding this comment

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

Hi sounds great to start seeing Windows support along. We have a lot of unixism in this repository though.

Would this be possible to add windows support to the CI too? You need to edit .bazelci/presubmit.yml, you can get the syntax of the file there.

output = ctx.actions.declare_file(ctx.label.name + ".wasm")
else:
output = ctx.actions.declare_file(ctx.label.name)
output = ctx.actions.declare_file(ctx.label.name + toolchain.binary_ext)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am surprised WASM test still pass as there is no declared extension corresponding: https://github.com/jelmansouri/rules_rust/blob/win_support/rust/platform/triple_mappings.bzl#L39

I don't really understand the WASM change though so I cannot tell if its missing tests or because the extension is not important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I have a couple changes coming up after to not use run_shell in the subset of rules we are using. (cc_library and cc_binary). Similarly to this change we did on go:
https://github.com/bazelbuild/rules_go/blob/master/go/private/rules/binary.bzl#L120
It's a great thing to add the CI and I'm really happy to do it!
Our goal is not to rely on genrules nor run_shell on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what is using the Windows CI to fail is the use of run_shell, my other that I did in our codebase to not use run_shell, needs to be redone given that the command used to run the compiler is gotten more complicated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Submitted some WIP to have a green CI, do you think it's ok if I get a similar change as in the go rule linked above in the function I added (will need to shuffle stuff around)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes this is fine. I also prefer genrule over run_shell as the later needs a posix shell.

@damienmg
Copy link
Collaborator

I had the change for more than a month, in the meantime this got added:
https://github.com/bazelbuild/rules_rust/pull/322/files
I'm not sure if it breaks my original change

I don't think it is broken, at least the CI is green.

@jelmansouri
Copy link
Contributor Author

The change has two parts to it:
Removing run_shell based rules since rustc doesn't behave when when launched through an msys shell to build an msvc based abi target.
Adding windows extension where necessary

Note that C++ has been chosen to not introduce more dependencies (a cc toolchain is necessary anyways to build rust code), there is a similar wrapper written in python for protoc, I'm planning to migrate it to rust or C++.
out_dir_tar is supported through the tar util posix systems only, I will discuss with @damienmg a clear path to remove out_dir_tar support.

Copy link
Collaborator

@damienmg damienmg left a comment

Choose a reason for hiding this comment

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

The structure of the change looks good I think this is the correct direction, do you mind splitting this in 3 PR though?

  • The c++ wrapper tool
  • The cargo build script wrapper change
  • The rule change to support windows

?

Thanks!

@jelmansouri
Copy link
Contributor Author

The c++ wrapper tool and the cargo build script wrapper change are hard to split, since the wrapper consumes the files generated by it, and I had to do small changes to the format of the output files.
I can split the format from removing the use of the shell command maybe you were referring to that?
The windows changes are overall the small part of the change and I can split them. Are you ok with that?

@damienmg
Copy link
Collaborator

The c++ wrapper tool and the cargo build script wrapper change are hard to split, since the wrapper consumes the files generated by it, and I had to do small changes to the format of the output files.
I can split the format from removing the use of the shell command maybe you were referring to that?
The windows changes are overall the small part of the change and I can split them. Are you ok with that?

I think we are on the same page. Let me try to rephrase a bit how I see the 3 independent changes:

  • Change in env format, which require a change in cargo_build_script and the rust wrapper
  • Replacement of the shell script by a C++ wrapper
  • Some windows support specifics

Depending on your preference you can include the drop of the tar file support in the C++ wrapper or as a separate change (it make sense to put it with the C++ wrapper as this comes with the reason for it). Dropping the support is just calling fail() if out_dir_tar is provided. With a message pointing out to cargo_build_script if people use it.

Copy link
Collaborator

@damienmg damienmg left a comment

Choose a reason for hiding this comment

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

Just some nits left, thanks a lot for following through for this change, very nice addition!

- "--enable_runfiles" # this is not enabled by default on windows and is necessary for the cargo build scripts
windows_targets: &windows_targets
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we plan to have multiple windows run? Maybe there is no need for the windows_targets indirection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to add test_targets, I'm still trying to fix rustdoct_test rules to be able to add them. But I prefer the change to go in first without this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok no worries, I am going to merge this PR as-is this is already a huge improvement over the status-quo.

"windows": ".exe",
"darwin": "",
# TODO(acmcarther): To be verified
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this TODO, darwin extension is definitely empty.

Suggested change
# TODO(acmcarther): To be verified

"windows": ".dll",
# TODO(acmcarther): To be verified
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

Suggested change
# TODO(acmcarther): To be verified

"windows": ".lib",
# TODO(acmcarther): To be verified
Copy link
Collaborator

Choose a reason for hiding this comment

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

Idem

Suggested change
# TODO(acmcarther): To be verified

@damienmg damienmg merged commit d2c4b14 into bazelbuild:master Jul 1, 2020
a1ph pushed a commit to a1ph/rules_rust that referenced this pull request Jul 3, 2020
It failed to parse empty depenv files due to how 'split' function works.
damienmg pushed a commit that referenced this pull request Jul 3, 2020
It failed to parse empty depenv files due to how 'split' function works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants