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

Windows updates #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

willtoth
Copy link

@willtoth willtoth commented Mar 22, 2021

Adding a few updates for better support on Windows, currently WIP.

Changes:

  • Enables param files, this is critical for Windows due to the command length limitation which is hit very easily when using STM32CubeMX drivers even for a basic project.
  • Improve runfile support for openocd tools. Windows does not do runfiles well in Bazel currently due to issues with symlinks. Details here.

TODO:

  • Decide if batch script with MANIFEST file is actually robust enough. I am definitely no expert with batch scripts, nor do I particularly enjoy working with them. Other options may be to use a library like this one and wrap openocd with that.
  • Need a better way to enable/disable param files support based on platform, as this is only required on Windows.

Copy link
Collaborator

@nathaniel-brough nathaniel-brough left a comment

Choose a reason for hiding this comment

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

This looks great! thanks for submitting. Just got a few comments and questions.

Need a better way to enable/disable param files support based on platform, as this is only required on Windows.

I'm not overly familiar with param files. Does it matter if this is enabled on linux or not? If not just go ahead and enable it.

Decide if batch script with MANIFEST file is actually robust enough. I am definitely no expert with batch scripts, nor do I particularly enjoy working with them. Other options may be to use a library like this one and wrap openocd with that.

It looks like we'd have to vendor some of that code out or do something similar as the target itself is 'test_only' and 'private'. In terms of the MANIFEST files, my experience with them is that they are relatively stable, so I'm happy to depend on them. If the format changes in future versions of bazel then we can deal with that when/if it happens.

# 2) Open the MANIFEST file (non-standard format, beware for future versions)
# 3) Find com_openocd and use the full path to the symlink
# 4) In batch script, cd to base of tool and call bin/openocd.exe directly
windows_script_prepend = """
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm going to have to properly learn batch scripting before I can reasonably review this. I don't fully understand what is going on here.

Copy link
Author

Choose a reason for hiding this comment

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

I'm added more comments to this snippet of code, and I'll move it out to a common function. I need the comments just to remember exactly how it works and I just put it together yesterday. Maybe someone more familiar with batch scripts can make sure I'm not totally off base :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

No worries. I've got a bit more time over the next couple days, so I should have a bit more time for reviews.

# A bit of a hacky way to do this... The issue is Windows does not support
# symlinks which does not work well for runfiles in particular. To enable them
# the user must use Developer Mode, also not ideal. Instead:
# 1) Use the 'symlink' as a generic path to the root of openocd
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to consolidate my understanding here does this use symlinks and hence require developer mode. Or is this simulating symlinks (with inverted quotes).

Copy link
Author

Choose a reason for hiding this comment

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

This does not use symlinks or developer mode.

The best that I can tell, when repository_ctx.symlink() is called, it simply copies the file to the new location. So this line creates a copy of the exe at the root of the openocd directory, but without the supporting files next to it

https://github.com/silvergasp/bazel-embedded/blob/34004ad4b06efa17450b64d21fb46d3a8a9f78ef/tools/openocd/openocd_repository.bzl#L48

This file is also the only entry in the MANIFEST file without making other changes, but its good enough to give a path to the actual files. So the batch script finds the entry that starts with com_openocd, then strips the fake symlink name and replaces is with /bin/openocd.exe

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll disable developer mode next time I'm booted on windows, and give this a proper look.

"url": "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.10.0-14/xpack-openocd-0.10.0-14-win32-x64.zip",
"sha256": "b195e3c3e9fe3f4fe9dfd9780ff08336ef8ed3015a76cc883d9e21e57c456f33",
"prefix": "",
"url": "https://github.com/ntfreak/openocd/releases/download/v0.11.0/openocd-v0.11.0-i686-w64-mingw32.tar.gz",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we leave this as using the xpack/eclipse distribution urls. Happy to update to v0.11.0 but I'd rather get the openocd binaries all from one source for consistency. The ntfreak distrobution only packages up the windows binaries for release whereas the xpack distribution packages for most OS's. See here for urls and sha's.

@nathaniel-brough
Copy link
Collaborator

Apologies for the delay here. I mostly work on a linux based system so the effort to boot into a windows machine is the main blocker for me here. The goto's in that batch script make me a little uncomfortable. I'm not sure if I would be able to maintain the batch script if I merge this in. I've been looking at how the rules_docker stuff works, and they seem to have found a relatively elegant way of supporting multiple different platforms without the host path seperator hacks that I've previously used.

Firstly they use this to get the full host path on both windows and linux. This is paired up with an environment variable set in their templated script.

Then they use a bunch of selects from a macro to configure based on the platform. Which I had no idea was possible, but I'm glad I do now.

What are your thoughts on a setup like this?

I should have some time over the next couple weeks to make some of those changes towards a 'rules_docker' approach. You are welcome to have a crack at it in the mean time.

Of your changes I'd like to use;

  • Adds windows implementation of print_all_features
  • Fixes command line length too long for Windows

But I'm not quite sold on the others.

@willtoth
Copy link
Author

willtoth commented Apr 8, 2021

I agree that is much nicer than the batch script and host path separator. I will try to put some time into this, but my own Windows usage my soon be very limited as well.

@willtoth
Copy link
Author

willtoth commented Apr 21, 2021

Trying to take a shot at this.

It looks like the rules_docker skylib is a bit different thatn the skylib repo, specifically:

https://github.com/bazelbuild/rules_docker/blob/8c3a8110a0c519929a7e79c39ac345a0f8c74d04/skylib/path.bzl#L88

I'm planning to just copy over some of the code here, unless you think we should just depend on rules_docker.

@willtoth
Copy link
Author

@silvergasp How is RUNFILES_DIR defined https://github.com/silvergasp/bazel-embedded/blob/master/tools/openocd/defs.bzl#L168

@nathaniel-brough
Copy link
Collaborator

Trying to take a shot at this.

It looks like the rules_docker skylib is a bit different thatn the skylib repo, specifically:

https://github.com/bazelbuild/rules_docker/blob/8c3a8110a0c519929a7e79c39ac345a0f8c74d04/skylib/path.bzl#L88

I'm planning to just copy over some of the code here, unless you think we should just depend on rules_docker.

I'm happy with something similar over here. If you are directly copying the files over please add a comment in the top of the file that matches their licence. It doesn't have to be the full license terms but at least a reference of where the file came from.

@nathaniel-brough
Copy link
Collaborator

nathaniel-brough commented Apr 26, 2021

I've got a bit more time to play with this. Just wondering where you got to with all this? It's looking like you've removed the Batch script in the latest commit. Is there anything that I can do to make this easier to push through, especially towards to approach that rules_docker uses?

willtoth and others added 5 commits April 24, 2024 23:15
This commit adds support for param files. This is important for
Windows since even the most basic STM32Cube project ends up
with more lines than Windows supports.
@willtoth willtoth marked this pull request as ready for review April 25, 2024 04:20
@willtoth
Copy link
Author

Also fixes #75 and #74

@willtoth
Copy link
Author

willtoth commented Apr 25, 2024

Looks like this repo may not have as much traction as it had when I first opened the PR, but 3 years later, its ready if you want to take a look @silvergasp

May be slightly more important now, since this is technically broken in newer bazel versions

@nathaniel-brough
Copy link
Collaborator

I'm super busy at the moment moving back to Australia. So I'll hopefully take another pass at it in the next 2-3 weeks.

I've switched over to rust for most of my new embedded projects, so I'm rarely using Bazel anymore and can't justify the time to actively work on this project. But I'm happy to review PRs when I get a spare minute.

@LandryNorris
Copy link

LandryNorris commented Apr 26, 2024

@willtoth The description of this PR mentions that it fixes the same issue as #68, but it looks like the change was pulled out of this branch. Is it expected that this PR will fail because the command line invocation for ar is too long with STM32CubeMX drivers? If this is expected, I could make a separate branch that merges the two together to unblock me on building for now.

@willtoth
Copy link
Author

@LandryNorris this is included in the PR already, though I noticed only for gcc, any chance you're actually building with clang?

@LandryNorris
Copy link

It's gcc. Here's the ar path: external\bazel_embedded\toolchains\gcc_arm_none_eabi\gcc_wrappers\windows\ar.bat. The project compiles successfully on Bazel 4, but fails with the ar command being too long (~8500 characters) when using Bazel 7.

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.

3 participants