This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Add rudimentary Swift bindings test case
AbandonedPublic

Authored by GeorgeLyon on Jun 29 2022, 3:39 PM.

Details

Summary

This commit adds a rudimentary Swift bindings test to MLIR. The basic model for Swift bindings is very similar to Python, in that they are both hidden behind a CMake flag (in Swift's case, MLIR_ENABLE_BINDINGS_SWIFT), and do not affect the build otherwise.

As a compiled, C-style language, Swift can be more deeply integrated into the build system than Python. Specifically, we can actually create Swift targets in CMake that are more-or-less indistinguishable from C and C++ targets (via add_llvm_executable and friends). This will eventually allow us to develop libraries in Swift that do not require a working Swift compiler to be run (assuming we statically link Swift's standard library).
One downside to adding Swift in this way, is that a few places in LLVM's build system add compile definitions and flags which are not compatible with Swift globally to any LLVM target. I have fixed the few such places where this affected Swift bindings for MLIR by using CMake's COMPILE_LANGUAGE generator feature, which allows us to specify directly that certain options or flags are only relevant to C and C++ sources.

Notably, this commit does not add the bindings themselves, just the initial test case demonstrating compiling a Swift target which depends on an MLIR library. My hope is that I can address feedback about how I am integrating with the build system independently of the bindings themselves, and upon merging this to main perhaps add this path to CI so new flags are not added in a way that is incompatible with Swift.

Diff Detail

Event Timeline

GeorgeLyon created this revision.Jun 29 2022, 3:39 PM
GeorgeLyon requested review of this revision.Jun 29 2022, 3:39 PM

Fix a comment

GeorgeLyon added a reviewer: stella.stamenova.

Remove some accidental debug code

Is the eventual end goal adding swift bindings to MLIR upstream?

Is the eventual end goal adding swift bindings to MLIR upstream?

Yes! Sorry if this wasn't clear.

rriddle requested changes to this revision.Jul 1 2022, 11:30 AM

Is the eventual end goal adding swift bindings to MLIR upstream?

Yes! Sorry if this wasn't clear.

Do you have a discourse link? If not can you post a formal RFC on the LLVM discourse? Feels like this is missing a lot of context.

This revision now requires changes to proceed.Jul 1 2022, 11:30 AM

Sure, I’ll post a discourse thread later today.

GeorgeLyon abandoned this revision.Jul 1 2022, 11:45 AM

I'll revisit this after some discussion on Discourse.