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

Add cross-compiling support for the windows toolchain #71584

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

hjyamauchi
Copy link
Contributor

Extend build.ps1 to enable cross-compile the windows toolchain. For example, building the Windows ARM64 toolchain on a Windows X64 machine.

@compnerd
Copy link
Member

@swift-ci please build toolchain Windows platform

@hjyamauchi hjyamauchi force-pushed the crosscompiling-buildps1 branch from 1623490 to 7211d06 Compare February 13, 2024 18:10
@hjyamauchi hjyamauchi requested a review from compnerd February 13, 2024 18:10
@hjyamauchi
Copy link
Contributor Author

@swift-ci please build toolchain Windows platform

@compnerd
Copy link
Member

CC: @shahmishal - as we do not currently have a toolchain that has ARM64 SDKs, we need to use the builds from The Browser Company. If we can roll a new release with the changes, we can adjust that URL.

@compnerd
Copy link
Member

@swift-ci please build toolchain Windows platform

utils/build.ps1 Outdated
$PinnedSHA256 = "006266d8c2a6a9c70e21b9d161ec35c07bcbb8a452b17e145899d814d07a29e7"
}
"ARM64" {
$PinnedBuild = "https://github.com/thebrowsercompany/swift-build/releases/download/20231117.3/installer-arm64.exe"
Copy link
Member

Choose a reason for hiding this comment

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

@shahmishal - this is the only ARM64 installer currently available that will run on ARM64. Since this script is used by developers and we are using it for ARM64 hosted builds, we do need to encode this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the hardcoded path to the ARM64 installer

utils/build.ps1 Show resolved Hide resolved
utils/build.ps1 Outdated
LLDB_PYTHON_EXE_RELATIVE_PATH = "python.exe";
LLDB_PYTHON_EXT_SUFFIX = ".pyd";
LLDB_PYTHON_RELATIVE_PATH = "lib/site-packages";
LLDB_TABLEGEN = (Join-Path -Path $BuildTools -ChildPath "lldb-tblgen.exe");
LLVM_CONFIG_PATH = (Join-Path -Path $BuildTools -ChildPath "llvm-config.exe");
LLVM_EXTERNAL_SWIFT_SOURCE_DIR = "$SourceCache\swift";
LLVM_INCLUDE_BENCHMARKS = "NO";
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need not to include the benchmarks now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This turned out to be unnecessary. Reverted.

Copy link
Member

Choose a reason for hiding this comment

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

I think that this might be needed still - this avoids unnecessary checks and configuration. I can do the change separately, but the problem was that one of the checks required execution which would not work with cross-compiling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That may be right. When I rerun without these changes, the build worked successfully.

@hjyamauchi hjyamauchi force-pushed the crosscompiling-buildps1 branch 2 times, most recently from 6906279 to dab2f44 Compare February 13, 2024 21:31
Python3_EXECUTABLE = "$python";
Python3_INCLUDE_DIR = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools\include";
Python3_LIBRARY = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools\libs\python39.lib";
Python3_ROOT_DIR = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools";
SWIFT_BUILD_SWIFT_SYNTAX = "YES";
Copy link
Member

Choose a reason for hiding this comment

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

I notice you are cross-compiling the new swift-syntax parser too. Do you have further CMake patches to make that work (similar to my #71552), pass in the extra flags manually, or is this disabled elsewhere?

Copy link
Member

Choose a reason for hiding this comment

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

Or is this just cross-compilation support to build SDKs, not to cross-compile the toolchain itself?

Copy link
Member

Choose a reason for hiding this comment

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

This is cross-compiling the toolchain and we did not find a need to add any additional flags.

Copy link
Member

Choose a reason for hiding this comment

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

This is cross-compiling the toolchain

OK

we did not find a need to add any additional flags.

No, I looked into it now and you were passing in extra SDK flags manually before and are still doing so now, as that's the only way this cross-compile works. You should try my cross-compilation pull out with your cross-compilation workflow, as I set the flags for a freshly-built cross-compilation SDK whereas it appears you manually pass in the extra flags for a prebuilt Windows ARM cross-compilation SDK. I think both should work fine together, as externally supplied flags should override the internal ones, but it would be good to verify that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@finagolfin Can you elaborate what "try my cross-compilation pull out with your cross-compilation workflow" means? How exactly do we "verify that"? I'd be happy to run or test something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@finagolfin I reran the cross-compile build with your patch #71552 and it was successful with no issues. The log also didn't say "CROSSCOMPILE". So it seems all good.

Copy link
Member

Choose a reason for hiding this comment

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

Great, what bootstrap mode are you using though?

Copy link
Contributor Author

@hjyamauchi hjyamauchi Feb 16, 2024

Choose a reason for hiding this comment

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

We don't use any bootstrap mode. We use the host tools.

Copy link
Member

Choose a reason for hiding this comment

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

OK, that is one of the bootstrapping modes, as you can see on the official linux CI, -- Bootstrapping: HOSTTOOLS. Yes, technically that doesn't make sense, but that was the wrong name that was chosen for this internal build variable, instead of something accurate like "Swift compiler source compilation mode."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha

@hjyamauchi
Copy link
Contributor Author

@swift-ci please build toolchain Windows platform

@hjyamauchi hjyamauchi force-pushed the crosscompiling-buildps1 branch 2 times, most recently from f9bcd16 to 6407d4a Compare February 26, 2024 21:57
@hjyamauchi
Copy link
Contributor Author

Rebased

@hjyamauchi
Copy link
Contributor Author

@swift-ci please build toolchain Windows platform

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

I think that this should be mostly fine, outside of the hardcoded Windows bit which interferes with other work. I suppose that I can try to address that, but I'd definitely appreciate it if you could try to proactively avoid some of that pain.

utils/build.ps1 Outdated
Comment on lines 706 to 695
TryAdd-KeyValue $Defines CMAKE_SYSTEM_NAME Windows
TryAdd-KeyValue $Defines CMAKE_SYSTEM_PROCESSOR $Arch.CMakeName
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, can we hoist this? I think that this might cause some trouble for adding Android support (see #72014).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@hjyamauchi hjyamauchi force-pushed the crosscompiling-buildps1 branch from 6407d4a to 7fdf14f Compare March 6, 2024 13:53
@hjyamauchi
Copy link
Contributor Author

@compnerd PTAL. The lastest revision is rebased and passes local cross-compiling tests.

@compnerd
Copy link
Member

@swift-ci please test

Copy link
Contributor

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

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

LGTM. Eventually it might make sense to have toolchain files and some examples of cache files that can set these variables rather than having a one-size-fits-all script force the values through.

@compnerd
Copy link
Member

LGTM. Eventually it might make sense to have toolchain files and some examples of cache files that can set these variables rather than having a one-size-fits-all script force the values through.

Which variables are you thinking of? I don't think that we want those files because the majority of the flags being passed are just paths that are dependent on how the build is being executed. The other flags that control what and how should be in cache files. The only exception that we currently have to that are the experimental modules.

@etcwilde
Copy link
Contributor

CMAKE__COMPILER_TARGET, the CMAKE_SYSTEM_PROCESSOR, etc. a lot of this is forced through the script when the cache and toolchain would do the job nicely. For the system processor, CMake docs explicitly call out using the toolchain file to set that variable. In this case it's fine, I'm just tired of the prescriptive nature of build-script making it really difficult to build things where you do need the customization, and then making it impossible to upstream things without breaking someone else.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

I think that with the changes for dependencies, this should be ready to go.

utils/build.ps1 Show resolved Hide resolved
@hjyamauchi hjyamauchi force-pushed the crosscompiling-buildps1 branch from 7fdf14f to 208a066 Compare April 17, 2024 16:34
@compnerd
Copy link
Member

@swift-ci please smoke test

@hjyamauchi hjyamauchi force-pushed the crosscompiling-buildps1 branch from 208a066 to f6ab729 Compare April 18, 2024 16:25
@hjyamauchi
Copy link
Contributor Author

Rebased and tested now.

@hjyamauchi
Copy link
Contributor Author

@swift-ci please test

@shahmishal
Copy link
Member

@swift-ci test windows

@hjyamauchi hjyamauchi merged commit 4364612 into swiftlang:main Apr 19, 2024
5 checks passed
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.

6 participants