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

Mach: Improve Visual Studio detection for non-standard-path installations #25300

Merged
merged 1 commit into from Jan 8, 2020

Conversation

@MeFisto94
Copy link
Contributor

MeFisto94 commented Dec 16, 2019

Improve locating the Visual Studio installation


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #25225
  • These changes do not require tests because testing build infrastructure is difficult
@highfive
Copy link

highfive commented Dec 16, 2019

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @paulrouget (or someone else) soon.

@highfive
Copy link

highfive commented Dec 16, 2019

Heads up! This PR modifies the following files:

@MeFisto94
Copy link
Contributor Author

MeFisto94 commented Dec 16, 2019

Explanation:
As you can see, the old code only relied on trying a fixed path to locate visual studio, but this fails for me.
This code essentially comes from https://searchfox.org/mozilla-central/rev/923eec8d2fb8078ebc7a33a9e1ce73eac01f7446/build/moz.configure/toolchain.configure#581 but has been simplified and cut down, so that it fits into servo.

I understand if you don't want to maintain/integrate these changes, but it might help others being stuck in the same situation. I've also did it so that the default behavior is kept and only replaced when the operation fails.
In theory, it would be better to only use the _ext version, because the current version depends on version names (Community, Professional) as well as requireing manual edits to it, everytime there is a new VS Version.
My code only requires maintaining "Current" for MSBuild Version and unfortunately Microsoft.VisualStudio.Component.Windows10SDK, which according to https://docs.microsoft.com/de-de/visualstudio/install/workload-component-id-vs-professional?view=vs-2019 is the name of Windows Universal C Runtime, which is required by servo according to the docs.

There are problems (apart from the "political" decision about maintenance and whethere this code should be touched or not):

  • I forgot that get_msbuild_version uses an even stranger version format instead of following the VS Version ("Current", but then also supporting "14.0", which isn't supported by find_highest_msvc_version). I will force-push this asap, but to me that feels odd.
  • mach.bat still uses a hardcoded version and runs vcvarsall.bat to set quite a few environmental variables. How is this code then required? Or put differently: Should mach.bat just rely on this code? I can only tell that locally running in mozilla-build, everything works, I use ./mach instead of mach.bat, though I cannot test mach.bat because it WOULD find vcvars from my 2015 install, which doesn't contain MSBuild though. Testing that would help me a lot.
  • I've read somewhere that Servo requires the Graphics Workload, but I couldn't find that in the docs. Maybe someone knows this cleary? Because then we could add Microsoft.VisualStudio.Component.Graphics.Tools to vswhere, so that only Installations with the required workloads are considered.
  • mozjs compilation fails [1] (I think this is unrelated to this change, relativesrcdir=mozpath.relpath(srcdir, obj.topsrcdir) or '.', -> This will always fail for me, as srcdir is ~/.cargo on C:\ and I've cloned servo to E:\

[1]:

Traceback (most recent call last):
  File "c:/Users/Marc/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/5906588/mozjs/js/src/../../configure.py", line 132, in <module>
    sys.exit(main(sys.argv))
  File "c:/Users/Marc/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/5906588/mozjs/js/src/../../configure.py", line 43, in main
    return config_status(config)
  File "c:/Users/Marc/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/5906588/mozjs/js/src/../../configure.py", line 127, in config_status
    return config_status(args=[], **encode(sanitized_config, encoding))
  File "c:\Users\Marc\.cargo\git\checkouts\mozjs-fa11ffc7d4f1cc2d\5906588\mozjs\python\mozbuild\mozbuild\config_status.py", line 146, in config_status
    the_backend.consume(definitions)
  File "c:\Users\Marc\.cargo\git\checkouts\mozjs-fa11ffc7d4f1cc2d\5906588\mozjs\python\mozbuild\mozbuild\backend\base.py", line 128, in consume
    if (not self.consume_object(obj) and
  File "c:\Users\Marc\.cargo\git\checkouts\mozjs-fa11ffc7d4f1cc2d\5906588\mozjs\python\mozbuild\mozbuild\backend\recursivemake.py", line 438, in consume_object
    consumed = CommonBackend.consume_object(self, obj)
  File "c:\Users\Marc\.cargo\git\checkouts\mozjs-fa11ffc7d4f1cc2d\5906588\mozjs\python\mozbuild\mozbuild\backend\common.py", line 134, in consume_object
    with self._get_preprocessor(obj) as pp:
  File "e:\mozilla-build\python\Lib\contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "c:\Users\Marc\.cargo\git\checkouts\mozjs-fa11ffc7d4f1cc2d\5906588\mozjs\python\mozbuild\mozbuild\backend\base.py", line 320, in _get_preprocessor
    srcdir_rel=mozpath.relpath(srcdir, mozpath.dirname(obj.output_path)),
  File "c:\Users\Marc\.cargo\git\checkouts\mozjs-fa11ffc7d4f1cc2d\5906588\mozjs\python\mozbuild\mozpack\path.py", line 33, in relpath
    rel = normsep(os.path.relpath(path, start))
  File "e:\Marc\Documents\Coding\servo\target\debug\build\mozjs_sys-88004c1deb65babf\out\_virtualenvs\init\lib\ntpath.py", line 529, in relpath
    % (path_prefix, start_prefix))
ValueError: path is on drive c:, start on drive e:
mozmake: *** [makefile.cargo:197: maybe-configure] Error 1
thread 'main' panicked at 'assertion failed: result.success()', C:\Users\Marc\.cargo\git\checkouts\mozjs-fa11ffc7d4f1cc2d\5906588\build.rs:133:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
@MeFisto94 MeFisto94 force-pushed the MeFisto94:improve-msvc-detection branch from ed26599 to 22af70b Dec 16, 2019
@saschanaz
Copy link
Contributor

saschanaz commented Dec 16, 2019

I think the existing detection code isn't needed if vswhere is used. (👍)

@jdm
Copy link
Member

jdm commented Dec 16, 2019

The mozjs build failure happens when your CARGO_HOME directory is on a different drive than your servo working directory.

@jdm
jdm approved these changes Dec 16, 2019
vers = find_highest_msvc_version_ext()
for version in sorted(vers, key=lambda tup: float(tup[1])):
return version
print("Can't find MSBuild.exe installation under %s. Try so specify the VSINSTALLDIR and VisualStudioVersion" +

This comment has been minimized.

Copy link
@jdm

jdm Dec 16, 2019

Member

Let's say "Please set the VSINSTALLDIR and VisualStudioVersion environment variables." instead.


vers = find_highest_msvc_version_ext()
for version in sorted(vers, key=lambda tup: float(tup[1])):
return version

This comment has been minimized.

Copy link
@jdm

jdm Dec 16, 2019

Member

Let's write this as:

versions = sorted(vers, key=lambda tup: float(tup[1]))
if not versions:
    print(...)
    sys.exit(1)
return versions[0]

This comment has been minimized.

Copy link
@MeFisto94

MeFisto94 Dec 16, 2019

Author Contributor

Should I replace vers here by the direct function call?

This comment has been minimized.

Copy link
@jdm

jdm Dec 16, 2019

Member

I don't mind the way it is.

@jdm jdm assigned jdm and unassigned paulrouget Dec 16, 2019
@MeFisto94 MeFisto94 force-pushed the MeFisto94:improve-msvc-detection branch from 22af70b to 0a80dd9 Dec 16, 2019
@jdm
Copy link
Member

jdm commented Dec 16, 2019

@bors-servo
Copy link
Contributor

bors-servo commented Dec 16, 2019

📌 Commit 0a80dd9 has been approved by jdm

@MeFisto94
Copy link
Contributor Author

MeFisto94 commented Dec 16, 2019

What about the two remaining things (which could be follow ups to this PR):

  • Does servo require the graphics workload?
  • mach.bat?
@jdm
Copy link
Member

jdm commented Dec 16, 2019

I am not aware of any requirement for the graphics workload. It's not clear to me what we can do differently with mach.bat.

@bors-servo
Copy link
Contributor

bors-servo commented Dec 17, 2019

Testing commit 0a80dd9 with merge 29d2ff1...

bors-servo added a commit that referenced this pull request Dec 17, 2019
Mach: Improve Visual Studio detection for non-standard-path installations

Improve locating the Visual Studio installation

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25225
- [X] These changes do not require tests because testing build infrastructure is difficult
@saschanaz
Copy link
Contributor

saschanaz commented Dec 17, 2019

The mozjs build failure happens when your CARGO_HOME directory is on a different drive than your servo working directory.

Is this a reply for my comment? Not sure how relevant it is...

@jdm
Copy link
Member

jdm commented Dec 17, 2019

No, it's a reply to the part of the earlier comment that mentions a failure to build mozjs_sys.

@bors-servo
Copy link
Contributor

bors-servo commented Dec 17, 2019

💔 Test failed - status-taskcluster

bors-servo added a commit that referenced this pull request Dec 17, 2019
Mach: Improve Visual Studio detection for non-standard-path installations

Improve locating the Visual Studio installation

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25225
- [X] These changes do not require tests because testing build infrastructure is difficult
@bors-servo
Copy link
Contributor

bors-servo commented Dec 17, 2019

💔 Test failed - status-taskcluster

@MeFisto94
Copy link
Contributor Author

MeFisto94 commented Dec 18, 2019

Speaking of mach.bat, in my opinion, we could delete everything before

servo/mach.bat

Line 49 in 79408fa

:mach

The reason is, that this searches for visual studio installations the old/legacy way and calls vcvars.bat.
I suspect this is so that MSBUILD is on PATH.
This will, however, fail early and thus not profit from the improved detection.
At the same time it's unnecessary to double-check for Visual Studio Installations.

In my experiments, having vcvars.bat excluded didn't break anything, especially since the code already locates the path to VS and uses that one (no need to have them on PATH, wouldn't work for me anyway [path limited to 1024 chars...]).

So we could do one of two things (or leave it as it is, of course):

  • Do thorough testing and exclude the vcvars.bat and see if the build breaks under any condition for anyone in their specific environment
  • Just continue with that legacy without thinking if it's required and just execute the .bat file from the python file (short after find_highest_msvc_version).
bors-servo added a commit that referenced this pull request Dec 23, 2019
Launch vcvarsall.bat for the recognized VS Installation Directory from python instead of making mach.bat try that on hardcoded paths.

Move the Execution of vcvars (which sets up the environment for visual studio tools) from mach.bat to python, so that ./mach works under mozilla-build and that #25300 can be used.
---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25360 #25336
- [X] These changes do not require tests because changes to build infra
@jdm
Copy link
Member

jdm commented Jan 8, 2020

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Jan 8, 2020

Testing commit 0a80dd9 with merge 71e8aca...

bors-servo added a commit that referenced this pull request Jan 8, 2020
Mach: Improve Visual Studio detection for non-standard-path installations

Improve locating the Visual Studio installation

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25225
- [X] These changes do not require tests because testing build infrastructure is difficult
@bors-servo
Copy link
Contributor

bors-servo commented Jan 8, 2020

💔 Test failed - status-taskcluster

@jdm
Copy link
Member

jdm commented Jan 8, 2020

@bors-servo retry

  • network failure
@bors-servo
Copy link
Contributor

bors-servo commented Jan 8, 2020

Testing commit 0a80dd9 with merge 9f971f7...

bors-servo added a commit that referenced this pull request Jan 8, 2020
Mach: Improve Visual Studio detection for non-standard-path installations

Improve locating the Visual Studio installation

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25225
- [X] These changes do not require tests because testing build infrastructure is difficult
@bors-servo
Copy link
Contributor

bors-servo commented Jan 8, 2020

☀️ Test successful - status-taskcluster
Approved by: jdm
Pushing 9f971f7 to master...

@bors-servo bors-servo merged commit 0a80dd9 into servo:master Jan 8, 2020
2 checks passed
2 checks passed
Community-TC (pull_request) TaskGroup: success
Details
homu Test successful
Details
@bors-servo bors-servo mentioned this pull request Jan 8, 2020
0 of 5 tasks complete
@MeFisto94 MeFisto94 deleted the MeFisto94:improve-msvc-detection branch Jan 9, 2020
bors-servo added a commit that referenced this pull request Jan 9, 2020
Launch vcvarsall.bat for the recognized VS Installation Directory from python instead of making mach.bat try that on hardcoded paths.

Move the Execution of vcvars (which sets up the environment for visual studio tools) from mach.bat to python, so that ./mach works under mozilla-build and that #25300 can be used.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25360 #25336
- [X] These changes do not require tests because changes to build infra
bors-servo added a commit that referenced this pull request Mar 24, 2020
Launch vcvarsall.bat for the recognized VS Installation Directory from python instead of making mach.bat try that on hardcoded paths.

Move the Execution of vcvars (which sets up the environment for visual studio tools) from mach.bat to python, so that ./mach works under mozilla-build and that #25300 can be used.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25360 #25336
- [X] These changes do not require tests because changes to build infra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.