Skip to content

Fix multi-arch cross-compiling #13108

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

Closed
wants to merge 2 commits into from
Closed

Conversation

zbowling
Copy link
Contributor

@zbowling zbowling commented Nov 28, 2017

On platforms without fat binaries (anything but Darwin), we now build
and install stdlibs for each arch in it's own folder. Namely
lib/swift/<platform>/<arch> instead of lib/swift/<platform>.

(Split from #12955)

@@ -327,7 +327,7 @@ function(_add_variant_link_flags)
${ARGN})

precondition(LFLAGS_SDK MESSAGE "Should specify an SDK")
precondition(LFLAGS_SDK MESSAGE "Should specify an architecture")
precondition(LFLAGS_ARCH MESSAGE "Should specify an architecture")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed an unrelated copy/paste bug with this arg.

"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR}"
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR}")

if("${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if I should gate on elf or gate on mach. @compnerd windows?

Copy link
Member

Choose a reason for hiding this comment

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

PE/COFF doesn't have fat binaries either. I think that we should make this a Mach check.

Copy link
Contributor

@gparker42 gparker42 Dec 1, 2017

Choose a reason for hiding this comment

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

Lines 1650 and 1743 use an IS_DARWIN check instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I can switch to that.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Driver parts look okay to me. I'll let Ross and others comment on the CMake.

@@ -1016,6 +1016,17 @@ static void getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
getPlatformNameForTriple(TC.getTriple()));
}

/// On Darwin we link fat libs in the root of the library path and on other OS
/// targets we look up libraries in the target arch's subfolder.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: This comment doesn't really describe the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah true. What I was thinking when I changed where we used it and not what the function does.

# Note this thin library.
list(APPEND THIN_INPUT_TARGETS ${VARIANT_NAME})
if (SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC)
# Add dependencies on the (not-yet-created) custom lipo target.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment can't be right. This is inside the non-Darwin no-lipo case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good catch. Copy-pasta.

@compnerd
Copy link
Member

compnerd commented Dec 3, 2017

I will try to take a closer look at this soon. But, we should try to get this patch taken care of soon. There is at least one patch from me (#12480) and one from @troughton (#13140) which is trying to address the problems caused by the fat vs thin binary handling in the build.

@zbowling
Copy link
Contributor Author

zbowling commented Dec 3, 2017

@compnerd Yeah, I see what you are doing in that other patch. I'll try to fix this one up really quick.

@zbowling
Copy link
Contributor Author

zbowling commented Dec 3, 2017

Fixed issues. can someone kick off the CI bot for me? I can't test locally this weekend.

@phausler
Copy link
Contributor

phausler commented Dec 4, 2017

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2017

Build failed
Swift Test OS X Platform
Git Sha - ce53ad3f70deb1c26d9929f7cb1f66e875454209

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2017

Build failed
Swift Test Linux Platform
Git Sha - ce53ad3f70deb1c26d9929f7cb1f66e875454209

@phausler
Copy link
Contributor

phausler commented Dec 4, 2017

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2017

Build failed
Swift Test Linux Platform
Git Sha - 99710c535006b9a53c954df412a545a6cb906515

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2017

Build failed
Swift Test OS X Platform
Git Sha - 99710c535006b9a53c954df412a545a6cb906515

@phausler
Copy link
Contributor

phausler commented Dec 4, 2017

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2017

Build failed
Swift Test OS X Platform
Git Sha - 47f1cf21b5eeaca32e73d843861122222570151b

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2017

Build failed
Swift Test Linux Platform
Git Sha - 47f1cf21b5eeaca32e73d843861122222570151b

@zbowling
Copy link
Contributor Author

zbowling commented Dec 4, 2017

not sure how to invoke @swift-ci so it compiles this PR with foundation using this PR together swiftlang/swift-corelibs-foundation#1354

@gparker42
Copy link
Contributor

please test with the following pull request:
swiftlang/swift-corelibs-foundation#1354

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2017

Build failed
Swift Test OS X Platform
Git Sha - 42a003164f08bdf5750b435c16fbc870532a4cb4

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2017

Build failed
Swift Test Linux Platform
Git Sha - 42a003164f08bdf5750b435c16fbc870532a4cb4

@zbowling
Copy link
Contributor Author

zbowling commented Dec 4, 2017

doh. dependency in unit tests was broken. fixed

@gparker42
Copy link
Contributor

please test with the following pull request:
swiftlang/swift-corelibs-foundation#1354

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2017

Build failed
Swift Test OS X Platform
Git Sha - 1fd55bb8dbd5f1d57b4dfeb13cf4106a86010a15

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2017

Build failed
Swift Test Linux Platform
Git Sha - 1fd55bb8dbd5f1d57b4dfeb13cf4106a86010a15

@zbowling
Copy link
Contributor Author

zbowling commented Dec 4, 2017

Funny linker error in foundation:

../buildbot_linux/foundation-linux-x86_64/Foundation/Foundation/NSIndexSet.swift.o: In function `_T010Foundation10NSIndexSetC21_enumerateWithOptionsSiSgAA013NSEnumerationF0V_AA8_NSRangeV5rangexm9paramTypeq_m06returnK0q_x_SpyAA8ObjCBoolVGtc5blocktr0_lFySicq_x_AOtccfU_ySicfU_AI_ytTg5': ../buildbot_linux/foundation-linux-x86_64/Foundation/Foundation/NSIndexSet.swift.o:(.text+0x2b2f): undefined reference to `_T0s17_AnyCollectionBoxC6_indexs01_a5IndexC0_psAD_p_s5Int64V8offsetBytF'

Curious why this worked on a previous build.

Demangle says it's: Swift._AnyCollectionBox._index(Swift._AnyIndexBox, offsetBy: Swift.Int64) -> Swift._AnyIndexBox

I'm wondering if this is supposed to get generated by libswiftSwiftOnoneSupport.so and it's not picking it up now.

@zbowling
Copy link
Contributor Author

zbowling commented Dec 4, 2017

updated this branch to current master. I'm wondering if this is just the branch foundation is on is out of sync with this one. should be ok to test again.

@gparker42
Copy link
Contributor

please test with the following pull request:
swiftlang/swift-corelibs-foundation#1354

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2017

Build failed
Swift Test Linux Platform
Git Sha - d048dd6f5a429fe46651f648392f797c6da8a970

@@ -1016,6 +1016,17 @@ static void getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
getPlatformNameForTriple(TC.getTriple()));
}

/// Get the runtime library link path with the target triple's specific arch
/// library folder.
static void getRuntimeLibraryPathWithArch(SmallVectorImpl<char> &runtimeLibPath,
Copy link
Member

Choose a reason for hiding this comment

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

Can you call this getRuntimeSharedLibraryPathWithArch to match getRuntimeStaticLibraryPathWithArch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the non "WithArch" variant above this one calls doesn't use the "Shared" prefix. I could rename everything but it seemed more invasive.

// directory for searching for binaries. This is the same as the import
// path for modules.
SearchPathOpts.RuntimeLibraryPath = LibPath.str();
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Why not sink the LibPath calculation into the Triple.isOSDarwin() or else case respectively?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I'll look at writing this be more clear with one branch instead of two. I was over optimizing trying to avoid creating two string allocs for the non-Darwin path at the sake of some clarity.

Basically:

if Darwin:
  RuntimeLibraryPath = /lib/swift/(platform)
else:
  RuntimeLibraryPath = /lib/swift/(platform)/(arch)

RuntimeLibraryImportPath = /lib/swift/(platform)/(arch)

@compnerd
Copy link
Member

compnerd commented Dec 5, 2017

Please test with the following pull request:
swiftlang/swift-corelibs-foundation#1354

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 5, 2017

Build failed
Swift Test Linux Platform
Git Sha - db0242ead12a38e1852578724db7b01f8fff2450

@swift-ci
Copy link
Contributor

swift-ci commented Dec 5, 2017

Build failed
Swift Test OS X Platform
Git Sha - db0242ead12a38e1852578724db7b01f8fff2450

@zbowling
Copy link
Contributor Author

zbowling commented Dec 5, 2017

I think one of the tests failed because it's not cleaning. A previous version created a symlink in an unfortunate spot that will confuse the "RUN: ln -s" statements in the test.

The other test I'm not sure why it fails. It's not failing that way locally on my Ubuntu 14.04 machine.

// RUN: ln -s %t/libabc.so %t/rsrc/%target-sdk-name/%target-cpu
// RUN: ln -s %platform-module-dir/../* %t/rsrc/%target-sdk-name/%target-cpu
// RUN: ln -s %platform-module-dir/../%target_cpu/* %t/rsrc/%target-sdk-name/%target-cpu
Copy link
Contributor Author

Choose a reason for hiding this comment

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

doh. %target-cpu and not %target_cpu

@zbowling
Copy link
Contributor Author

zbowling commented Dec 5, 2017

Seems like a regression to something discussed in #282

On platforms without fat binaries (anything but Darwin), we now build
and install stdlibs for each arch in it's own folder. Namely
lib/swift/<platform>/<arch> instead of lib/swift/<platform>.
@zbowling
Copy link
Contributor Author

zbowling commented Dec 5, 2017

squashed and rebased this branch so I can update my fuchsia branch based on these commits

@compnerd
Copy link
Member

Please test with the following pull request:
swiftlang/swift-corelibs-foundation#1354

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 056a367

@zbowling
Copy link
Contributor Author

Please test with the following pull request:
swiftlang/swift-corelibs-foundation#1354

@swift-ci please smoke test linux

@zbowling
Copy link
Contributor Author

I'm not sure what this test is doing that is failing on the linux bot. The module maps generated are working on debain machines I've tested just fine but the test fails.

@furkanozbay
Copy link

@swift-ci please test

@CodaFi
Copy link
Contributor

CodaFi commented Dec 18, 2017

Drive-by log restoration. Don’t mind me

@CodaFi
Copy link
Contributor

CodaFi commented Dec 18, 2017

Please test with the following pull request:
swiftlang/swift-corelibs-foundation#1354

@swift-ci please smoke test Linux platform

@compnerd
Copy link
Member

Do we want to split this up and get in part of the patch earlier? The build portion would be extremely useful for me as it allows me to build just part of the windows targets (e.g. just the x86_64 or ARM target).

@zbowling
Copy link
Contributor Author

zbowling commented Jan 8, 2018

@compnerd it's very intertwined and already split up a lot so far. going to try and investigate this last test that is failing. it's some kind of intermediate thing testing some kind of module metadata that I don't really understand or something but the final product seems to working fine on all archs so it's weird.

@alblue
Copy link
Contributor

alblue commented Jan 26, 2018

@swift-ci please test linux

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 056a367

@zbowling
Copy link
Contributor Author

zbowling commented Feb 7, 2018

I have some changes to swiftpm, libdispatch, and xctest (in additional to the current foundation change already) that go along with this change to teach them about the linux arch folder. Still not sure what is broken this unit test though.

@CodaFi
Copy link
Contributor

CodaFi commented Nov 21, 2019

Closing this due to age and inactivity, both here and on the corresponding Foundation PR.

@CodaFi CodaFi closed this Nov 21, 2019
@allevato allevato deleted the multi_arch branch October 7, 2020 19:37
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.