- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 266
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 universal prebuilt Mac package (x86_64 + arm64) #3958
Merged
+214
−103
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Cross-compiles the iOS default libraries, copies them to the install dir and | ||
# extends ldc2.conf. | ||
# | ||
# Required env vars: | ||
# - ARCH | ||
# - IOS_DEPLOYMENT_TARGET | ||
# - PARALLEL_JOBS | ||
|
||
steps: | ||
- script: | | ||
set -ex | ||
cd .. | ||
export PATH="$PWD/ninja:$PATH" | ||
triple="$ARCH-apple-ios$IOS_DEPLOYMENT_TARGET" | ||
if [[ "$ARCH" == "arm64" ]]; then | ||
sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk" | ||
else | ||
sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk" | ||
fi | ||
# use bootstrap-ldc, which is guaranteed to be native | ||
bootstrap-ldc/bin/ldc-build-runtime --ninja -j $PARALLEL_JOBS \ | ||
--buildDir=build-libs-ios \ | ||
--dFlags="-mtriple=$triple" \ | ||
--ldcSrcDir=$BUILD_SOURCESDIRECTORY \ | ||
CMAKE_SYSTEM_NAME=iOS \ | ||
CMAKE_OSX_SYSROOT="$sysroot" \ | ||
CMAKE_OSX_ARCHITECTURES=$ARCH \ | ||
CMAKE_OSX_DEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET \ | ||
BUILD_LTO_LIBS=ON | ||
mkdir installed/lib-ios-$ARCH | ||
cp -a build-libs-ios/lib/*.{a,dylib,o} installed/lib-ios-$ARCH | ||
section=" | ||
\"$ARCH-apple-ios\": | ||
{ | ||
switches = [ | ||
\"-defaultlib=phobos2-ldc,druntime-ldc\", | ||
\"-Xcc=-target\", | ||
\"-Xcc=$triple\", | ||
\"-Xcc=-miphoneos-version-min=$IOS_DEPLOYMENT_TARGET\", | ||
\"-Xcc=-isysroot\", | ||
\"-Xcc=$sysroot\", | ||
]; | ||
lib-dirs = [ | ||
\"%%ldcbinarypath%%/../lib-ios-$ARCH\", | ||
]; | ||
rpath = \"%%ldcbinarypath%%/../lib-ios-$ARCH\"; | ||
};" | ||
echo "$section" >> installed/etc/ldc2.conf | ||
cat installed/etc/ldc2.conf | ||
displayName: 'Cross-compile iOS default libraries, copy to install dir and extend ldc2.conf' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# Each step starts in the checked-out source directory, | ||
# environment variables aren't persisted across steps. | ||
# | ||
# Required env vars: | ||
# - CI_OS | ||
# - IOS_DEPLOYMENT_TARGET | ||
|
||
steps: | ||
|
||
- checkout: self | ||
submodules: false | ||
fetchDepth: 50 | ||
|
||
# Download x86_64 and arm64 artifacts | ||
- task: DownloadPipelineArtifact@2 | ||
inputs: | ||
artifactName: $(CI_OS)-x86_64 | ||
targetPath: artifacts | ||
displayName: Download x86_64 artifact | ||
- task: DownloadPipelineArtifact@2 | ||
inputs: | ||
artifactName: $(CI_OS)-arm64 | ||
targetPath: artifacts | ||
displayName: Download arm64 artifact | ||
|
||
# Extract & merge | ||
- script: | | ||
set -ex | ||
|
||
mkdir ldc2-{x86_64,arm64} | ||
tar -xf artifacts/ldc2-*-x86_64.tar.xz --strip 1 -C ldc2-x86_64 | ||
tar -xf artifacts/ldc2-*-arm64.tar.xz --strip 1 -C ldc2-arm64 | ||
|
||
cp -R ldc2-x86_64 ldc2-universal | ||
cd ldc2-universal | ||
|
||
# rename/copy lib dirs | ||
mv lib lib-x86_64 | ||
cp -R ../ldc2-arm64/lib lib-arm64 | ||
cp -R ../ldc2-arm64/lib-ios-arm64 . | ||
|
||
# merge executables to universal ones | ||
for exe in bin/*; do | ||
rm $exe | ||
lipo -create -output $exe ../ldc2-x86_64/$exe ../ldc2-arm64/$exe | ||
done | ||
|
||
# ldc2.conf: replace the default section and add extra sections | ||
sections=" | ||
default: | ||
{ | ||
// default switches injected before all explicit command-line switches | ||
switches = [ | ||
\"-defaultlib=phobos2-ldc,druntime-ldc\", | ||
]; | ||
// default switches appended after all explicit command-line switches | ||
post-switches = [ | ||
\"-I%%ldcbinarypath%%/../import\", | ||
]; | ||
// default directories to be searched for libraries when linking | ||
lib-dirs = []; | ||
// default rpath when linking against the shared default libs | ||
rpath = \"\"; | ||
}; | ||
|
||
\"x86_64-apple-\": | ||
{ | ||
switches = [ | ||
\"-defaultlib=phobos2-ldc,druntime-ldc\", | ||
\"-Xcc=-target\", | ||
\"-Xcc=x86_64-apple-macos\", | ||
]; | ||
lib-dirs = [ | ||
\"%%ldcbinarypath%%/../lib-x86_64\", | ||
]; | ||
rpath = \"%%ldcbinarypath%%/../lib-x86_64\"; | ||
}; | ||
|
||
\"arm64-apple-\": | ||
{ | ||
switches = [ | ||
\"-defaultlib=phobos2-ldc,druntime-ldc\", | ||
\"-Xcc=-target\", | ||
\"-Xcc=arm64-apple-macos\", | ||
]; | ||
lib-dirs = [ | ||
\"%%ldcbinarypath%%/../lib-arm64\", | ||
]; | ||
rpath = \"%%ldcbinarypath%%/../lib-arm64\"; | ||
}; | ||
|
||
\"arm64-apple-ios\": | ||
{ | ||
switches = [ | ||
\"-defaultlib=phobos2-ldc,druntime-ldc\", | ||
\"-Xcc=-target\", | ||
\"-Xcc=arm64-apple-ios$IOS_DEPLOYMENT_TARGET\", | ||
\"-Xcc=-miphoneos-version-min=$IOS_DEPLOYMENT_TARGET\", | ||
\"-Xcc=-isysroot\", | ||
\"-Xcc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk\", | ||
]; | ||
lib-dirs = [ | ||
\"%%ldcbinarypath%%/../lib-ios-arm64\", | ||
]; | ||
rpath = \"%%ldcbinarypath%%/../lib-ios-arm64\"; | ||
};" | ||
|
||
perl -0777 -pi -e "s|\\ndefault:\\n.+?\\n\\};|$sections|s" etc/ldc2.conf | ||
cat etc/ldc2.conf | ||
cd .. | ||
displayName: Extract & merge artifacts | ||
|
||
# Smoke tests | ||
- script: | | ||
set -ex | ||
echo 'void main() { import std.stdio; writefln("Hello world, %d bits", size_t.sizeof * 8); }' > hello.d | ||
for os in macos ios$IOS_DEPLOYMENT_TARGET; do | ||
for arch in x86_64 arm64; do | ||
triple="$arch-apple-$os" | ||
ldc2-universal/bin/ldc2 -mtriple="$triple" hello.d | ||
ldc2-universal/bin/ldc2 -mtriple="$triple" hello.d -link-defaultlib-shared | ||
done | ||
done | ||
displayName: Run x86_64/arm64 macOS/iOS cross-compilation smoke tests | ||
|
||
# Pack & publish artifact | ||
- script: | | ||
set -ex | ||
mkdir newArtifacts | ||
if [ "${BUILD_SOURCEBRANCH:0:10}" = "refs/tags/" ]; then | ||
artifactID=${BUILD_SOURCEBRANCH:11} | ||
else | ||
artifactID=${BUILD_SOURCEVERSION:0:8} | ||
fi | ||
artifactName=ldc2-$artifactID-$CI_OS-universal | ||
mv ldc2-universal $artifactName | ||
chmod -R go=rX $artifactName | ||
sudo chown -R root:wheel $artifactName | ||
tar -cJf newArtifacts/$artifactName.tar.xz --options='compression-level=9' $artifactName | ||
displayName: Pack | ||
- publish: newArtifacts | ||
artifact: $(CI_OS)-universal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like less trouble than anticipated; according to CI, it's fine on x86_64 hosts. Some quick smoke tests on actual Apple Silicon (cross-compiling & -linking to all 4 targets) would be appreciated; if you have time, maybe also checking the arm64 package and that it can target iOS too. Pinging @p0nce, @dnadlinger, @schveiguy.
CI artifact(s) downloadable from https://dev.azure.com/ldc-developers/ldc/_build/results?buildId=3437&view=artifacts&pathAsName=false&type=publishedArtifacts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work fine for building a Phobos Hello World on 12.2.1/arm64, for both arm64 and x86_64 targets (with the 1.29.0-git-788b8ef binaries from your comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All tests on macOS Monterey 12.0.1, Xcode 13.0, M1
what I haven't tested = the Universal package on x86_64 host.
I'm testing intel-intrinsics in unitest-release mode, to avoid the -g bug in Monterey.
(Reference run with LDC 1.28 x86_64
dub test -a x86_64-apple-macos -b unittest-release
=> OKdub test -a arm64-apple-macos -b unittest-release
=> OK)LDC is Universal Binary
dub test -a x86_64-apple-macos -b unittest-release --compiler /Users/guill/Desktop/compilers/test/ldc2-788b8ef0-osx-universal/bin/ldc2
=> OKdub test -a arm64-apple-macos -b unittest-release --compiler /Users/guill/Desktop/compilers/test/ldc2-788b8ef0-osx-universal/bin/ldc2
=> OKdub test -a x86_64-apple-ios -b release --compiler /Users/guill/Desktop/compilers/test/ldc2-788b8ef0-osx-universal/bin/ldc2
=> OK, successfully link and runs, crash the withdyld[1918]: DYLD_ROOT_PATH not set for simulator program
which sounds alright.dub test -a arm64-apple-ios -b release --compiler /Users/guill/Desktop/compilers/test/ldc2-788b8ef0-osx-universal/bin/ldc2
=> OK, successfully link and crash the unittests with error code 9, probably my faultSo yeah I guess it can become the one and only LDC on macOS :)
Also tests the now obsolete packages:
LDC arm64 package
dub test -a x86_64-apple-macos -b unittest-release --compiler /Users/guill/Desktop/compilers/test/ldc2-788b8ef0-osx-arm64/bin/ldc2
=> OK, link failure as expected, as arm64 LDC doesn't have x86_64 target.dub test -a arm64-apple-macos -b unittest-release --compiler /Users/guill/Desktop/compilers/test/ldc2-788b8ef0-osx-arm64/bin/ldc2
=> link failure, not sure why, not a concern if universal supersedes that
LDC is x86_64
dub test -a x86_64-apple-macos -b unittest-release --compiler /Users/guill/Desktop/compilers/test/ldc2-788b8ef0-osx-x86_84/bin/ldc2
=> OKdub test -a arm64-apple-macos -b unittest-release --compiler /Users/guill/Desktop/compilers/test/ldc2-788b8ef0-osx-x86_84/bin/ldc2
=> OK, link failure, but expected since x86_64 package can't target arm64 anymore.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this isn't working for me on OSX 12.3.1. Specifically, the -g flag doesn't work still (get linker errors).
Note also, with a previous LDC, if I set the environment variable:
MACOSX_DEPLOYMENT_TARGET=11
it worked. In this version, that workaround doesn't work. So I would not be able to use this binary.The specific error is:
See #3864 for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for testing. - This doesn't affect/fix #3864 at all; if there are changes compared to before, that's either because of LLVM 14 or some further Xcode changes or whatever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jacob-carlborg any insights here? You were the one I think who figured out the workaround last time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Off-topic, but there is another change for this CI artifact here compared to the latest releases - the macOS image for building LDC, druntime and Phobos was bumped from 10.15 to 11.x, and so the Xcode SDK version with it.
MACOSX_DEPLOYMENT_TARGET
during the build was raised from 10.9 to 10.12 for the x86_64 package; still at 11.0 for the arm64 package.One workaround is adding
-preserve-dwarf-line-section=false
to the cmdline /ldc2.conf
file, implying no file/line infos in druntime exception backtraces. A debugger would presumably still offer those infos.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10.12 as target is more than OK, because once notarized a lot of software doesn't launch on 10.11 anyway except if you use a special flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately no. I think the best way forward, assuming the
-preserve-dwarf-line-section=false
flag works, is to read the debug info from the object files instead of the executable, that's what the debugger is doing. Debug info can also be compiled to its own .dSYM file for distribution. The best would be if all three methods were supported by druntime. @Geod24 is working on this, IIRC.