A parent repo for apple/swift fork & MIOJSLibs. Contains additional tests and scripts for transpiling native swift libs.
Cloning this repo
Clone with an additional flag git clone --recurse-submodules https://github.com/miolabs/MIOSwiftTranspiler.git
.
That ensures that it's cloned together with the submodule MIOJSLibs.
Cloning the swift repo (separate for now) & building the executable
We've decided not to include the swift submodule, because it was failing when running the
./swift/utils/update-checkout --clone
for some reason. For now, you need to clone it separately.
Go to the parent directory of MIOSwiftTranspiler and run mkdir swift-source && cd swift-source
. Then
clone our fork of the apple swift repo git clone https://github.com/miolabs/swift.git
. Then run another command
that swift needs to work cd .. && ./swift/utils/update-checkout --clone
.
Then you need to build the C++ executable. We need to additionally include the --ios
flag, so that we can target UIKit.
Run ./swift/utils/build-script --release-debuginfo --ios
.
After the executable is built, you need to switch the branch cd swift && git checkout ts-transpiler-synced
.
I'm trying to keep it up to date, so that the only different file is lib/AST/ASTDumper.cpp
. That should help us
avoid problems related to building the executable (if the branch is not up to date, all hell breaks loose,
because the code and libs aren't in sync).
After switching the branch, you need to rebuild the executable with ninja one final time as described in Usage.
The initial setup is complete 🎉🎉.
Rebuilding the executable after updating swift repo/changing a .cpp file
cd ./swift-source/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64
ninja swift
Testing our transpiler - both local & github tests
cd ./test
mocha
Transpiling a given file
../swift-source/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swiftc -dump-ast -O -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks example.swift
For UIKit:
../swift-source/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swiftc -dump-ast -O -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk -target arm64-apple-ios12.2 -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks example.swift
Outputting the AST tree (untouched ASTDumper)
swiftc -dump-ast -O example.swift
Building the transpiled swift libraries
node ./include/build-bodies/build.js from-step-2
Running templates/project
cd ./MIOJSLibs/templates/project
Then to start the basic http server serving the files npm start
.
To compile the project's ts - for the first time, run npm run init
.
Later on you can just do npm run tsc
to run the tsc compiler in watch mode.
The project needs to include two sets of libraries: MIOJSLibs and the one generated by the transpiler.
The first time and then any time transpiler gets updated, run npm run build-swift-libs
The first time and then any time MIOJSLibs get updated, run npm run build-miojs-libs