-
Notifications
You must be signed in to change notification settings - Fork 69
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
BUG: Use meson compile wrapper on Windows #371
Conversation
Ah yes, now that I see this, I am relying on
and that worked quite nicely. |
Isn't there anywhere a command that can be used like If it does not exist, someone should write it. |
You would really only use the Also I would argue, having to hardcode the path to vcvarsall.bat or add another dependency to do this for me, is worse than adding just |
Right now the easisest way to do this is which doesn't work on bash and also not on powershell. |
I agree with @lithomas1 on the UX point, the function Invoke-VSDevEnvironment {
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$installationPath = & $vswhere -prerelease -legacy -latest -property installationPath
$Command = Join-Path $installationPath "Common7\Tools\vsdevcmd.bat"
& "${env:COMSPEC}" /s /c "`"$Command`" -arch=amd64 -no_logo && set" | Foreach-Object {
if ($_ -match '^([^=]+)=(.*)') {
[System.Environment]::SetEnvironmentVariable($matches[1], $matches[2])
}
}
}
Invoke-VSDevEnvironment |
There are good reasons why we moved from IIUC, this PR is relevant only for CI setups where there are multiple compilers installed. For my projects I use an action to setup the required environment variables. Therefore, the problem is limited to CI setups with multiple compilers and using some shell where the action does not work. Would an action that works for setting up the environment variables for an UNIX-like shell be an acceptable solution? |
I'm actually using it in Appveyor, so a GHA action isn't helpful. That said, I haven't looked under the hood to see what Perhaps adding native support in |
I would still prefer sticking to meson. IIUC, the I'm not against using an action, but meson's solution is just better, since it is CI-provider agnostic, and also should be shell agnostic. I think the only argument made against it was |
If the issue presents itself almost exclusively in CI setups, I don't understand the reason for the reluctance in using a simple external tool to solve the issue in a flexible way. Taking the implementation of |
Here it is https://github.com/dnicolodi/vsenv No documentation and no tests, but it should be doing exactly what I was describing above. |
I don't think it does? Anyone wanting to use MSVC on Windows may run into this. The Visual Studio activation is run on every subcommand say the docs. The downside of that is timing (from gh-328: meson compile, 1 second. ninja, 0.005 seconds), the upside is that things work. For non-editable builds, the 1 sec. gain is not interesting compared to the UX gains of things not mysteriously breaking when you, for example, run dev commands in a freshly opened Git Bash shell. However, I agree that for editable builds where |
The fact that the issue is mostly encountered in CI context was reported as a justification for not having an optimal UX. I just repeated the statement. If this is something that users need to use, the Documenting that the MSVC compiler needs to be in the PATH (when other compiler suites are found on the PATH) is the correct solution. I already opened a bug about this a while ago, see #224. Note that the I'm really not that keen to compromises motivated to fixup basic compilation environment setup requirements. If you want to run a compiler, the compiler needs to be found on the PATH. If your compiler vendor makes it ridiculously hard to have that setup properly, please go complain to your compiler or OS vendor. |
I don't think that's a reasonable stance. I also very much dislike how complex it is to use MSVC from the command line, and that MSVC is not on the PATH by default when you install it, but that won't be changed by Microsoft because we don't like it. So we should try our best to make it work. And it already works with plain Meson out of the box when MSVC is the only installed compiler - we're just actively avoiding that as a performance optimization by calling UX-wise, We still may have an issue then (not actually clear to me), which is that it doesn't work out of the box without that argument. Which I think Meson itself does seem to handle. So using I don't have a Windows machine at hand, it'd be great to be able to check if for regular usage without |
Sorry, I misunderstood. I thought that the issue was only present with more than one compiler installer on the system. However, obviously, the issue is also when only MSVS is present as there is nothing that setups the environment also in this case when meson-python invoked I still think that having the compilers in the PATH is a more than reasonable solution, and that vendors should be pressured to provide a solution to easily do that. However, indeed, I don't see this happening any time soon. It would be great if Windows and Visual Studio users would make their license money worth and demand things to work reasonably, but I have the impression that open source maintainers are easier to reach that the Microsoft technical support. Let's revert back to use |
Yeah, there's a tradeoff between performance and complexity here. I don't have a clear preference - I think I agree with what you propose here, but I could see us going another way later perhaps. The third option is to default to One other thing I'd like to do is add a test with code that is MSVC-specific and only runs on Windows with MSVC installed. That way we're dogfooding whatever we do here. |
I'm not sure I proposed a solution, I think I have more questions than answers on this issue. IMHO the reasonable options are:
I think 2. is the best option. The execution time penalty for editable installations on systems other than Windows is too large to pay, and having a different compilation command for editable and regular builds is much more surprising than a difference based on the platform. Having an user option for this seems a lot of work for very little gain. I'll polish @lithomas1 patch and add a documentation patch on top. |
Ah okay, I misunderstood what you meant. Yes, I think (2) seems like the way to go at the moment, +1 for that. |
@dnicolodi You should be able to push to my branch directly if you want (I ticked the box allowing maintainers to push). |
Another possible solution came to mind:
Drawbacks of this approach are that this is a little bit more code that needs to be maintained in meson-python and the code would have to de duplicated in every editable package loader, although a hundred lines of code do not really seem to be that significant in the broad picture. Advantages are that we don't need to pay the |
Maybe we can start with (2) at least, and consider later if (4) is needed? Alternatively, we could help with optimizing |
FYI I am +1 of bringing back Also, IMO having
Can you link to those recommendations? It might be relevant when deciding this. I honestly don't really remember anything major, just that it doesn't actually invoke other build backends on itself. I do not wish to argue about this, so please just take my opinion as-is and refer to the other maintainers to make the final call. |
@FFY00 we're already on the same page about this one - we all agree now it's a breaking change and we'll fix it before the release. |
Okay, so, here's my opinion. Let's roll back the @lithomas1 could you update the PR to use This is a release blocker, so I'd like to get this solved soon, so that we can finally have a stable release with editable installs support. And thank you very much for reporting the issue and opening the PR! |
I opened #373 to track the editable installs speedup. Let's release with |
@rgommers @lithomas1 and I already agreed on the way forward. Why is that decision being disregarded? |
Indeed. The funny thing is that it seem to depend on the optimization level: that should be the only difference between using |
One more data point: |
a4d29cb
to
338ede8
Compare
Either I've been staring at this too long or there is something unusual going on: the link command that fails and the one that succeeds are identical. |
e924405
to
a3abba0
Compare
Found it! The issue does not depend on how the Visual Studio environment gets activated. It really depends on the buildtype option. I think there is still some confusion in the interplay of the debug, optimization, and buildtype options on the Meson side. The issue is caused by the compiler options used for After removing the common options, the default Clearly the |
From https://mesonbuild.com/Builtin-options.html#base-options
That's what sets /MDd. |
Thanks, I was not aware of that option. Based on that, I would say that Meson is doing what it is asked to do. I was a bit surprised that setting For meson-python, I really don't know what the best way forward is. It seems that, if we set |
One thing that I don't understand is that |
a3abba0
to
30fda4b
Compare
It is also surprising that |
4ebb5b5
to
d49aa11
Compare
fe1eb11
to
6848361
Compare
With #383 merged, this can be merged without the workaround for the linking problem. |
418d71c
to
5f96c46
Compare
Rebased once more. @rgommers is there any reason for not merging this? |
I don't think so - I'll make time for a final review(/merge) later today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests pass and this all looks quite good to me. Just a few very minor things I noticed (docs, typos). @dnicolodi please have a look and feel free to merge when those are addressed or if I'm wrong about them.
# pass them to the --ninja-args option | ||
assert cmd[-1].startswith('--ninja-args=') | ||
cmds.append(cmd[:2]) | ||
args.append(ast.literal_eval(cmd[-1].split('=')[1])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slightly painful I guess, but fine in a test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are you referring to? The not-so-nice part is marshaling the arguments into the format expected by Meson. Parsing them back is just a consequence of that. However, the code for either does not look that horrible.
@@ -44,6 +44,20 @@ building a Python wheel. User options specified via ``pyproject.toml`` | |||
or via Python build front-end config settings override the | |||
``meson-python`` defaults. | |||
|
|||
When building on Windows, ``meson-python`` invokes the ``ninja`` | |||
command via the ``meson compile`` wrapper. When the GCC or the LLVM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it actually only GCC/LLVM, or any other compiler? I'd expect the latter. If so, maybe rephrase like "When no other compiler known to Meson (e.g., GCC or Clang-cl) is found on ...."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same info is repeated under Examples, so if editing here then it needs editing further down too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of the code implementation, we quite literally check for shutil.which
with any of cc, gcc, clang, clang-cl. The remaining autodetected default compilers for C are icl and pgcc, but icl ships with its own cl.exe (super "helpful" as noted by the code comments in detect.py) and meson will prefer cl.exe over pgcc anyway, if it can.
The --vsenv code is not kept in sync with detect.py's list of default compiler search names, whether it "should" do so is another question (that I don't have an opinion on, to be clear. :D)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't found detailed documentation for the compiler auto detection. I had a look at the code, which behaves as @eli-schwartz describes https://github.com/mesonbuild/meson/blob/eb472a133f45826a246b40c3d775eebf098fd6b1/mesonbuild/utils/vsenv.py#L43-L51 I don't know how much of this is appropriate to document on the meson-python side, given that it is not explicitly documented and that I don't know how much of it is susceptible of change in Meson. I thought that GCC and LLVM covered the most popular cased and anyone using a less common compiler would know what they are doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explantions both - looks like we're good then with the current docs.
I don't know how much of this is appropriate to document on the meson-python side, given that it is not explicitly documented and that I don't know how much of it is susceptible of change in Meson.
agreed
The meson compile wrapper is required on Windows to setup the MSVC compiler environment. Using the --ninja-args option to meson compile allows to provide the exact same semantics for the compile arguments. The format in which ninja command line arguments need to be passed to --ninja-args makes the interface a bit awkward to use and adds some complexity to this otherwise simple patch.
5f96c46
to
cd81e7b
Compare
Necessary if e.g. the user passes requests vsenv from meson setup.
(I guess I could restrict this to only when vsenv is requested in setup, but this needs thought as to how it would work with existing builddirs. I don't remember OTOH if we reconfigure the build dir if it exists already).
With this, pandas should be getting close to greenish again.
I still need to add a test for this, but this should be the right idea.