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

Enable libdispatch on x86 #4

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Enable libdispatch on x86 #4

wants to merge 2 commits into from

Conversation

triplef
Copy link
Member

@triplef triplef commented Jun 2, 2021

No description provided.

@triplef triplef marked this pull request as draft July 2, 2021 10:41
@triplef
Copy link
Member Author

triplef commented Aug 5, 2021

@davidchisnall could you do me a favor when you get a chance and take a look at these linker errors I’m getting for libdispatch when building it for 32-bit with the MSVC toolchain?

This is being built in a x86 Developer Command Prompt, but for some reason the linker command from CMake ends up with a bunch of extra LIBPATH options referencing the x64 toolchain. Can you think of anything that might cause this? I checked the CMake files of libdispatch but don’t see anything in that direction.

The CMake command should be the following, and the same setup works fine building libobjc2:

cmake .. ^
  -G Ninja ^
  -D CMAKE_BUILD_TYPE=Debug ^
  -D CMAKE_INSTALL_PREFIX="%INSTALL_PREFIX%" ^
  -D CMAKE_C_COMPILER=clang-cl ^
  -D CMAKE_CXX_COMPILER=clang-cl ^
  -D BUILD_SHARED_LIBS=YES ^
  -D INSTALL_PRIVATE_HEADERS=YES ^
  -D CMAKE_CXX_FLAGS_RELWITHDEBINFO="/Zi" ^
  -D CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO="/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF" ^
  -D BlocksRuntime_INCLUDE_DIR=%INSTALL_PREFIX%\include ^
  -D BlocksRuntime_LIBRARIES=%INSTALL_PREFIX%\lib\objc.lib ^

I’d appreciate your thoughts on this. Thank you!

@davidchisnall
Copy link
Member

All of those errors look like they're from the CRT. If you're using a recent CMake (3.20 or later?), it provides a cleaner way of specifying the target than depending on ambient bits of environment. If you specify -A {Win32,x64} then you can tell CMake which architecture to target. With -T ClangCL then you will use the clang toolchain that shipped with VS 2019 (this may need to be an optional install, but it's present on the GitHub-managed action runners, we're using it for snmalloc.

@triplef
Copy link
Member Author

triplef commented Aug 6, 2021

Thanks for the suggestion using the VS generator with -T ClangCL. Unfortunately though that is giving the exact same linker errors with -A Win32.

Btw. I also tried using that generator with libobjc2, but I’m getting the error "File not found - objc.pdb" when installing with the following command (even though the file is there in the Debug directory):
cmake --build . --config Debug --target install

@davidchisnall
Copy link
Member

The libobjc2 CMake contains numerous hacks because it requires a version of CMake that predates CMake's official support for Objective-C. Riccardo objected to moving it forward. At some point I will make a modern CMakeLists.txt and move the current one to CMakeLists.Riccardo for him to use. Most platforms now provide a mechanism for installing the latest cmake (it's the default everywhere except Ubuntu and it's in a snap there), so maintaining support for old versions is not particularly useful.

@triplef
Copy link
Member Author

triplef commented Oct 4, 2022

Feedback in the libobjc2 issue:

There was a time where the x86 build of libdispatch didn't work, but I believe all the issues have been resolved. Yes, this is a bit trickier to get right, but the following should give you a working build:
https://github.com/compnerd/swift-build/blob/master/build.cmd#L502
https://github.com/compnerd/swift-build/blob/master/build.cmd#L620-L639
with appropriate modifications of course.

FTR, the undefined symbol __DllMainCRTStartup is going to be fulfilled by msvcrt.lib.

From the above are a couple CMake options we’re not setting, e.g.:

  -D CMAKE_C_COMPILER_TARGET=i686-unknown-windows-msvc                          ^
  -D CMAKE_CXX_COMPILER_TARGET=i686-unknown-windows-msvc                        ^
  -D CMAKE_SYSTEM_NAME=Windows                                                  ^
  -D CMAKE_SYSTEM_PROCESSOR=i686                                                ^
  -D CMAKE_MT=mt                                                                ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants