ctaggart / rustup.rs

The Rust toolchain installer
0 stars 0 forks source link

create script to install C++ dependencies #1

Open ctaggart opened 6 years ago

ctaggart commented 6 years ago

It should be possible to run a command to install the C++ dependencies required by Rust. rust-init-exe could actually check kick off vs_installershell.exe modify.

Finding installed Visual C++ tools for Visual Studio 2017 https://blogs.msdn.microsoft.com/vcblog/2017/03/06/finding-the-visual-c-compiler-tools-in-visual-studio-2017/

image

trust PSGallery

Get-PSRepository
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

install VSSetup if not already

Install-Module VSSetup -Scope CurrentUser

It should be a simpler version of: https://github.com/Microsoft/visualfsharp/blob/master/scripts/Add-VisualStudioComponents.ps1

Visual Studio Where

& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" /?
Visual Studio Locator version 2.4.1+g2035d08a45 [query version 1.16.1163.30317]
Copyright (C) Microsoft Corporation. All rights reserved.

Usage: vswhere.exe [options]

Options:
  -all           Finds all instances even if they are incomplete and may not launch.
  -prerelease    Also searches prereleases. By default, only releases are searched.
  -products arg  One or more product IDs to find. Defaults to Community, Professional, and Enterprise.
                 Specify "*" by itself to search all product instances installed.
                 See https://aka.ms/vs/workloads for a list of product IDs.
  -requires arg  One or more workload or component IDs required when finding instances.
                 All specified IDs must be installed unless -requiresAny is specified.
                 See https://aka.ms/vs/workloads for a list of workload and component IDs.
  -requiresAny   Find instances with any one or more workload or components IDs passed to -requires.
  -version arg   A version range for instances to find. Example: [15.0,16.0) will find versions 15.*.
  -latest        Return only the newest version and last installed.
  -legacy        Also searches Visual Studio 2015 and older products. Information is limited.
                 This option cannot be used with either -products or -requires.
  -format arg    Return information about instances found in a format described below.
  -property arg  The name of a property to return. Defaults to "value" format.
                 Use delimiters ".", "/", or "_" to separate object and property names.
                 Example: "properties.nickname" will return the "nickname" property under "properties".
  -nologo        Do not show logo information. Some formats noted below will not show a logo anyway.
  -?, -h, -help  Display this help message.

Formats:
  json           An array of JSON objects for each instance (no logo).
  text           Colon-delimited properties in separate blocks for each instance (default).
  value          A single property specified by the -property parameter (no logo).
  xml            An XML data set containing instances (no logo).
& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
Visual Studio Locator version 2.4.1+g2035d08a45 [query version 1.16.1163.30317]
Copyright (C) Microsoft Corporation. All rights reserved.

instanceId: 65f9f796
installDate: 6/13/2018 12:06:30 PM
installationName: VisualStudio/15.7.4+27703.2035
installationPath: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise
installationVersion: 15.7.27703.2035
productId: Microsoft.VisualStudio.Product.Enterprise
productPath: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe
isPrerelease: 0
displayName: Visual Studio Enterprise 2017
description: Microsoft DevOps solution for productivity and coordination across teams of any size
channelId: VisualStudio.15.Release
channelUri: https://aka.ms/vs/15/release/channel
enginePath: C:\program files (x86)\microsoft visual studio\installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service
releaseNotes: https://go.microsoft.com/fwlink/?LinkId=660692#15.7.4
thirdPartyNotices: https://go.microsoft.com/fwlink/?LinkId=660708
updateDate: 2018-06-22T04:36:55.6258711Z
catalog_buildBranch: d15.7
catalog_buildVersion: 15.7.27703.2035
catalog_id: VisualStudio/15.7.4+27703.2035
catalog_localBuild: build-lab
catalog_manifestName: VisualStudio
catalog_manifestType: installer
catalog_productDisplayVersion: 15.7.4
catalog_productLine: Dev15
catalog_productLineVersion: 2017
catalog_productMilestone: RTW
catalog_productMilestoneIsPreRelease: False
catalog_productName: Visual Studio
catalog_productPatchVersion: 4
catalog_productPreReleaseMilestoneSuffix: 1.0
catalog_productRelease: RTW
catalog_productSemanticVersion: 15.7.4+27703.2035
catalog_requiredEngineVersion: 1.16.1187.57215
properties_campaignId: 1770200367.1527091722
properties_channelManifestId: VisualStudio.15.Release/15.7.4+27703.2035
properties_nickname:
properties_setupEngineFilePath: C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installershell.exe

latest install path

PS C:\Users\taggac\tmp> & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise

Visual Studio Installer

& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vs_installershell.exe" --help
Usage: C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installershell.exe --help [command [options]]

Commands:
  install    Installs a product
  modify     Modifies an installed product
  update     Updates an installed product
  repair     Repairs an installed product
  resume     Resumes a partial installation, usually after a system reboot
  uninstall  Uninstalls an installed product

Options:
  --installPath            The installation directory for the instance to act upon. For the install command, this is where the instance will be installed. For other commands, this is where the previously-installed instance was installed.  [string]
  --productId              The ID of the product for the instance that will be installed. This is required for the install command, ignored for other commands if --installPath is specified.  [string]
  --channelId              The ID of the channel for the instance that will be installed. This is required for the install command, ignored for other commands if --installPath is specified.  [string]
  --channelUri             The URI of the channel manifest.  This can be used for the install command; it is ignored for other commands.  [string]
  --installChannelUri      The URI of the channel manifest to use for the installation.  The URI specified by --channelUri (which must be specified when --installChannelUri is specified) will be used to detect updates.  If updates are not desired, --channelUri must be specified without an argument.  This can be used for the install command; it is ignored for other commands.  [string]
  --installCatalogUri      The URI of the catalog manifest to use for the installation.  If specified, the channel manager will attempt to download the catalog manifest from this URI before using the URI in the install channel manifest.  This parameter is used to support offline install, where the layout cache will be created with the product catalog already downloaded.  This can be used for the install command; it is ignored for other commands.  [string]
  --layoutPath             The layout directory to check for packages before attempting to download them using the location in the manifest. This can be used for the install command; it is ignored for other commands.  [string]
  --add                    This defines an artifact (group, workload, or component) that is to be added to the installation.  It can appear multiple times on the command line.

                           The required components of the artifact are installed, but not the recommended or optional components. You can control additional components globally using --includeRecommended and/or --includeOptional. For finer-grained control, you can append ";includeRecommended" and/or ";includeOptional" to the artifactId (e.g. "--add Workload1;includeRecommended" or "--add Workload2;includeOptional;includeRecommended").

                           It is optional for the install and modify commands, ignored for the update, repair and uninstall commands.  [string]
  --remove                 This defines an artifact (group, workload, or component) that is to be removed from the installation.  It can appear multiple times on the command line. It is optional for the install and modify commands, ignored for the update, repair and uninstall commands.  [string]
  --all                    Installs all workloads and all components.
  --allWorkloads           Installs all workloads and their required components, no recommended or optional components.
  --includeRecommended     Includes the recommended components for any workloads that are installed, but not the optional components.  The workloads are specified either with --allWorkloads or --add.
  --includeOptional        Includes the optional components for any workloads that are installed, but not the recommended components.  The workloads are specified either with --allWorkloads or --add.
  --campaign               The identifier of the campaign, for campaign tracking. If supplied, this ID will be logged with the installer's "AppLaunched" telemetry event.  [string]
  --activityId             An ID that can be used to correlate the installer command with an event in Visual Studio.  If supplied, this ID will be logged with the installer's "AppLaunched" event.  [string]
  --in                     The URI or path to a response file  [string]
  --version, -v            Writes the application's version number to the console and exits
  --passive, -p            If present, the command proceeds with UI, immediately and without user interaction. This option cannot be used with --quiet.
  --quiet, -q              If present, the command proceeds without UI.  Progress messages are written to stdout and error messages are written to stderr.  This option cannot be used with --passive.
  --norestart              If present, commands with --passive or --quiet will not automatically restart the machine (if required).  This is ignored if neither --passive nor --quiet are specified.
  --locale                 The locale to be displayed on the GUI.  [string]
  --focusedUi              If present, a minimal GUI will be displayed for a client to review before commiting the operation. This option cannot be used with --passive, --quiet, or --remove.
  --installSessionId       The sessionId from a previous instance of the client, for telemetry.  [string]
  --runOnce                Starts a new instance(process) of installer with current set of arguments except the runOnce argument.
  --addProductLang         This defines the language of an artifact (group, workload, or component) that is to be installed.  It can appear multiple times on the command line. It is optional for the install and modify commands, ignored for the update, repair and uninstall commands. If not present, the installation will use the machine locale.  [string]
  --removeProductLang      This defines the language of an artifact (group, workload, or component) that is to be removed.  It can appear multiple times on the command line. It is optional for the install and modify commands, ignored for the update, repair and uninstall commands.  [string]
  --nickname               This defines the nickname to assign to an installed product. The nickname cannot be longer than 10 characters. It is optional for the install command, ignored for the modify, update, repair and uninstall commands.  [string]
  --noUpdateInstaller      Prevents the installer from updating itself when quiet is specified. The installer will fail the command and return a non-zero exit code if noUpdateInstaller is specified with quiet when an installer update is required.
  --productKey             This defines the product key to use for an installed product. It is composed of 25 alphanumeric characters either in the format 'xxxxx-xxxxx-xxxxx-xxxxx-xxxxx' or 'xxxxxxxxxxxxxxxxxxxxxxxxx'. It is optional for the install and update commands, ignored for the repair, modify and uninstall commands.  [string]
  --cache                  If present, packages will be kept after being installed for subsequent repairs. This will override the global policy setting to be used for subsequent installs, repairs, or modifications. The default policy is to cache packages. This is ignored for the uninstall command.
  --nocache                If present, packages will be be deleted after being installed or repaired. They will be downloaded again only if needed and deleted again after use. This will override the global policy setting to be used for subsequent installs, repairs, or modifications. The default policy is to cache packages. This is ignored for the uninstall command.
  --noWeb                  No to any web download.
  --force, --updateFromVS  Force terminate any running Visual Studio processes.
  --pipe                   This defines the named pipe to connect  [string]
  --vsix                   URI or path to an additional vsix to install. Ignored if no command is provided.  [string]
  --flight                 A flight or flights to enable, along with the duration. eg "flight1;7d". This is only seeded during an install operation.  [string]
  --installerFlight        A flight or flights to enable, along with the duration. eg "flight1;7d"  [string]
  --path                   Allows for specifying custom install paths like cachePath. eg --path cachePath="C:\Program Files (x86)\Visual Studio"  [string]
ctaggart commented 6 years ago

I created a script. I'm currently calling it Add-VisualCpp.ps1. It must be run ad admin:

# start Visual Studio Installer to add the Rust dependencies
# currently just Visual C++

# get the latest Visual Studio installation path
$installationPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath

# install VC++
& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vs_installershell.exe" modify `
    --installPath $installationPath `
    --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64

Unfortunately, rustup-init.exe still does not detect it. I wonder which components it is detecting.

image

ctaggart commented 6 years ago

It doesn't really matter which VC++ toolset version you use, or which Universal CRT version you use, or which Windows SDK version you use as long as you have all three of them. However, it is generally better to have the newest versions when possible. https://github.com/rust-lang-nursery/rustup.rs/issues/1003#issuecomment-289825927

Based on this, I installed this two items and it worked.

image

Now I just need to update the script.

ctaggart commented 6 years ago

I don't know what the component name is for Windows Universal C Runtime. I'm not sure it was required. I'm hoping Microsoft.VisualStudio.Component.Windows10SDK is just an alias for the latest, currently Microsoft.VisualStudio.Component.Windows10SDK.17134.

This does the trick:

# start the Visual Studio Installer to install Rust dependencies
# current component names are:
#   VC++ 2017 version 15.7 v14.14 latest v141 tools
#   Windows 10 SDK (10.0.17134.0)

# get the latest Visual Studio installation path
$installationPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath

# launch the installer (must be admin)
& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vs_installershell.exe" modify `
    --installPath $installationPath `
    --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
    --add Microsoft.VisualStudio.Component.Windows10SDK
Diggsey commented 6 years ago

See here: https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-community

Looks like the unversioned Microsoft.VisualStudio.Component.Windows10SDK component is actually the "Windows Universal C Runtime`, whilst the versioned ones are the actual SDK.