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

Build and install swift-testing in toolchains #75515

Merged
merged 9 commits into from
Aug 10, 2024

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jul 26, 2024

(Supersedes #74582)

  • Include swift-testing to update-checkout's main scheme
  • (build-script) Add SwiftTesting product to swift_build_support and integrate it to the build pipeline
  • (build.ps1) Add Build-SwiftTestingMacros and Build-SwiftTesting functions, and integrate it to the pipeline
  • Testing just-built swift-testing is not implemented in this PR.

Build presets:

  • For toolchain packaging
    • mixin_linux_installation
    • mixin_osx_package_base
  • For CI testing:
    • buildbot_all_platforms,tools=RA,stdlib=RA
    • buildbot_incremental,tools=RA,stdlib=RA
    • buildbot_incremental_linux

Install locations:

  • macOS (Dedicated directories to precede Testing.framework in the Xcode SDK):
    ├── usr/lib/swift/macosx/testing
    │                        ├── Testing.swiftmodule
    │                        │   ├── ${MODULE_TRIPLE}.swiftdoc
    │                        │   ├── ${MODULE_TRIPLE}.swiftinterface
    │                        │   └── ${MODULE_TRIPLE}.swiftmodule
    │                        └── libTesting.dylib
    └── usr/lib/swift/host/plugins/testing
                                   └── libTestingMacros.dylib
    
  • Linux (Following XCTest):
    ├── usr/lib/swift/linux
    │                 ├── Testing.swiftmodule
    │                 │   ├── ${MODULE_TRIPLE}.swiftdoc
    │                 │   └── ${MODULE_TRIPLE}.swiftmodule
    │                 └── libTesting.so
    └── usr/lib/swift/host/plugins
                           └── libTestingMacros.so
    
  • Windows (Following XCTest scheme + plugin in the toolchain):
    ├── Platforms/${SDK_VERSION}/Windows.platform/Developer/Library/Testing-{SWIFT_TESTING_VERSION}
    │   └─── usr
    │        ├─── ${BIN_ARCH} // e.g. 'bin64'
    │        │    └── Testing.dll
    │        └─── lib/swift/windows
    │             ├─── ${LIB_ARCH} // e.g. 'x86_64'
    │             │    └── Testing.lib
    │             └─── Testing.swiftmodule
    │                  ├── ${MODULE_TRIPLE}.swiftdoc
    │                  └── ${MODULE_TRIPLE}.swiftmodule
    └─── Toolchains/${TOOLCHAIN_VERSION}/usr/bin
         └── TestingMacros.dll
    

@rintaro rintaro force-pushed the add-swift-testing branch 6 times, most recently from 243d971 to b8740cf Compare August 3, 2024 03:00
@rintaro rintaro force-pushed the add-swift-testing branch from b8740cf to f11ef1e Compare August 3, 2024 04:46
@rintaro rintaro changed the title [WIP] Build and install swift-testing in toolchains Build and install swift-testing in toolchains Aug 3, 2024
@rintaro rintaro marked this pull request as ready for review August 3, 2024 14:15
@rintaro rintaro requested a review from shahmishal as a code owner August 3, 2024 14:15
@rintaro
Copy link
Member Author

rintaro commented Aug 5, 2024

@rintaro rintaro requested review from compnerd, edymtt and bnbarham August 5, 2024 17:10
Copy link
Contributor

@edymtt edymtt left a comment

Choose a reason for hiding this comment

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

Looks good to me with regard to the build-script changes.


@classmethod
def get_dependencies(cls):
return [swift.Swift]
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for incorporating my feedback from the original PR!

@rintaro
Copy link
Member Author

rintaro commented Aug 5, 2024

@rintaro
Copy link
Member Author

rintaro commented Aug 5, 2024

@rintaro rintaro force-pushed the add-swift-testing branch from 04e364a to 74a36f8 Compare August 5, 2024 21:20
@rintaro
Copy link
Member Author

rintaro commented Aug 5, 2024

@swift-ci Please smoke test

@rintaro rintaro force-pushed the add-swift-testing branch from 74a36f8 to b70f07e Compare August 5, 2024 21:30
@rintaro
Copy link
Member Author

rintaro commented Aug 5, 2024

@rintaro
Copy link
Member Author

rintaro commented Aug 5, 2024

@rintaro
Copy link
Member Author

rintaro commented Aug 5, 2024

Copy link
Contributor

@stmontgomery stmontgomery left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you so much for picking up this effort!

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.

The windows build support changes look good modulo minor tweak.

@@ -2358,6 +2418,7 @@ if (-not $ToBatch) {
}

if (-not $SkipBuild) {
Invoke-BuildStep Build-SwiftTestingMacros $HostArch
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this next to the call to Build-SwiftTesting above?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't move this right next to Build-SwiftTesting call because it is for $WindowsSDKArchs not $HostArch. To what line you want to move this exactly?

Copy link
Member

Choose a reason for hiding this comment

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

Wait, why is it being built for each architecture for the SDK? The macros run at compile time, so we should only have to build it for the host that the toolchain is being built for.

Copy link
Member Author

@rintaro rintaro Aug 6, 2024

Choose a reason for hiding this comment

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

Yes, TestingMacros is built for the host only, Testing is built for each SDK arch. That's how I implemented. Am I missing anything?

Copy link
Member

Choose a reason for hiding this comment

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

The macros should be running with the compiler (host) not the SDK environment (target). So, I'm not sure I understand why we are building it in all these cases.

@rintaro
Copy link
Member Author

rintaro commented Aug 6, 2024

rintaro added 3 commits August 8, 2024 13:13
* Remove SwiftSyntax product dependency
* Correct CMAKE_BUILD_TYPE
 * Basically following XCTest scheme.
 * Build TestingMacro separately from Testing library and install it to
   the toolchain's `bin`
 * Testing swift-testing itself is TODO
@rintaro rintaro force-pushed the add-swift-testing branch 3 times, most recently from d17634f to 9aa6f06 Compare August 8, 2024 22:44
@rintaro rintaro force-pushed the add-swift-testing branch 2 times, most recently from 45c1be3 to bd5b4b0 Compare August 9, 2024 04:01
@rintaro
Copy link
Member Author

rintaro commented Aug 9, 2024

@rintaro rintaro force-pushed the add-swift-testing branch from bd5b4b0 to 9460969 Compare August 9, 2024 04:25
@rintaro
Copy link
Member Author

rintaro commented Aug 9, 2024

@rintaro
Copy link
Member Author

rintaro commented Aug 9, 2024

@rintaro
Copy link
Member Author

rintaro commented Aug 9, 2024

@rintaro
Copy link
Member Author

rintaro commented Aug 9, 2024

@rintaro
Copy link
Member Author

rintaro commented Aug 9, 2024

self._build_impl(host_target)

# For Darwin host, 'build' is only called for the builder.
# Manually iterate tor the cross compile hosts.
Copy link
Member Author

@rintaro rintaro Aug 9, 2024

Choose a reason for hiding this comment

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

Suggested change
# Manually iterate tor the cross compile hosts.
# Manually iterate the cross compile hosts.

and other places

@swiftlang swiftlang deleted a comment from xedin Aug 9, 2024
@swiftlang swiftlang deleted a comment from xedin Aug 9, 2024
@swiftlang swiftlang deleted a comment from xedin Aug 9, 2024
self.install_with_cmake(['install'], install_prefix)


class SwiftTestingMacros(product.Product):
Copy link
Contributor

Choose a reason for hiding this comment

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

(Optional) I would suggest to put the classes for SwiftTesting macros in a separate file, to maintain the convention that one file targets one build product.

self._install_impl(target)


class SwiftTestingMacrosImpl(cmake_product.CMakeProduct):
Copy link
Contributor

Choose a reason for hiding this comment

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

(Optional) Impl in this and SwiftTestingImpl can suggest this implements a build-script-impl product -- but I cannot think of a better alternative

Suggested change
class SwiftTestingMacrosImpl(cmake_product.CMakeProduct):
class SwiftTestingMacrosCMakeShim(cmake_product.CMakeProduct):

for target in self.args.cross_compile_hosts:
self._build_impl(target)

def _install_impl(self, host_target):
Copy link
Contributor

Choose a reason for hiding this comment

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

(Optional) In this and other places, _impl can suggest this is part of a build-script-impl product

Suggested change
def _install_impl(self, host_target):
def _install_with_cmake(self, host_target):

@@ -293,7 +293,7 @@ def target_for_platform(self, platform, arch, include_version=True):
arch, self.args.darwin_deployment_version_xros)
return target

def generate_darwin_toolchain_file(self, platform, arch):
def generate_darwin_toolchain_file(self, platform, arch, version=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

(Optional) It may make sense to state the intent of the version parameter so not to "overload" it with additional meanings in the future

Suggested change
def generate_darwin_toolchain_file(self, platform, arch, version=None):
def generate_darwin_toolchain_file(self, platform, arch, macos_deployment_version=None):

@@ -429,7 +434,8 @@ def generate_linux_toolchain_file(self, platform, arch):

return toolchain_file

def generate_toolchain_file_for_darwin_or_linux(self, host_target):
def generate_toolchain_file_for_darwin_or_linux(
self, host_target, override_deployment_version=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

(optional) override_deployment_version may imply this applies to Linux

Suggested change
self, host_target, override_deployment_version=None):
self, host_target, override_macos_deployment_version=None):

def build(self, host_target):
override_version = None
if host_target.startswith('macosx'):
override_version = '10.15'
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to override this only if the macOS deployment version is lower than the desired one -- this way if the default changes or the user uses a newer one we are not stuck with an old version

This suggestion is an expedient way to achieve this in this context -- we should likely prefer the functions defined in https://github.com/swiftlang/swift/blob/main/utils/build_swift/build_swift/versions.py

Suggested change
override_version = '10.15'
def version_parse(version_string):
return list(map(lambda x: int(x), version_string.split(".")))
if version_parse(self.args.darwin_deployment_version_osx) < (10, 15):
override_version = '10.15'

Copy link
Contributor

@edymtt edymtt Aug 9, 2024

Choose a reason for hiding this comment

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

Taking a stab using the Version class:

Suggested change
override_version = '10.15'
from build_swift.build_swift.versions import Version
if Version(self.args.darwin_deployment_version_osx) < Version('10.15'):
override_version = '10.15'

@rintaro rintaro force-pushed the add-swift-testing branch from 9460969 to 2e6cc34 Compare August 9, 2024 21:40
Also, build them for all hosts including cross compiling host.
@rintaro rintaro force-pushed the add-swift-testing branch from 2e6cc34 to e98c5ea Compare August 9, 2024 21:43
@rintaro
Copy link
Member Author

rintaro commented Aug 9, 2024

@rintaro rintaro merged commit 1c6552f into swiftlang:main Aug 10, 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