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

[glib] Support cross-compiling Objective C code using Meson #33313

Merged
merged 2 commits into from
Aug 25, 2023

Conversation

qmfrederik
Copy link
Contributor

The glib port uses Objective C code and the Meson build system. You'll end up cross compiling glib when compiling for x64 osx on an arm64 osx machine, or vice versa.

For this to work, an Objective C compiler needs to be set in the Meson cross file.

vcpkg generates this file based on the
scripts/buildsystems/meson/meson.template.in template, and expects the MESON_OBJC CMake variable to be set.

That's the job of z_vcpkg_meson_set_proglist_variables in scripts/cmake/vcpkg_configure_meson.cmake. It will only generate data for an Objective C compiler if:

  • The Languages argument includes OBJC
  • CMake has detected a Objective C compiler, and has set VCPKG_DETECTED_CMAKE_OBJC_COMPILER

To make this work, this patch:

  • Enables the OBJC and OBJCXX language on Apple platforms
  • Updates the call to vcpkg_configure_meson in the glib port file to include the OBJC OBJCXX languages.

Fixes #26147 Fixes #20341 Based on #26259 Based on TechSmith@27dee35

Tested on an arm64 mac to compile glib for x64 macos

@qmfrederik
Copy link
Contributor Author

/cc @Naville @ekilmer @dchengTSC @mike-malburg as you've been involved in similar conversations.

Comment on lines 11 to 16
enable_language(C)
enable_language(CXX)
if(APPLE)
enable_language(OBJC)
enable_language(OBJCXX)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

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

@ras0219-msft: I think this needs to be configurable somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Neumann-A If we don't want enable ObjC on macOS by default, would a better alternative be to add support for ObjC to the port files that need it? E.g. in this case I just add it to ports/glib/portfile.cmake?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably yes. Other ports do that on a port level basis with ASM and Fortran

Comment on lines 14 to 16
if(APPLE)
list(APPEND VCPKG_LANGUAGES "OBJC")
list(APPEND VCPKG_LANGUAGES "OBJCXX")
endif()
Copy link
Contributor

Choose a reason for hiding this comment

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

This always enable OBJC and OBJCXX on macosx running unnecessary compiler checks. You can use list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS "-DVCPKG_LANGUAGES=C;CXX;OBJC;OBJCXX") from the portfile or in vcpkg_configure_meson to enable additional languages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS "-DVCPKG_LANGUAGES=C;CXX;OBJC;OBJCXX") in the port file didn't seem to work; as cmake_get_vars seems to always initialise that to C;CXX

Setting an -DVCPKG_ENABLE_OBJC variable and having cmake_get_vars append OBJC to that list did do the trick, though.

@jimwang118
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jimwang118 jimwang118 added the category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist label Aug 23, 2023
The glib port uses Objective C code and the Meson build system.
You'll end up cross compiling glib when compiling for x64 osx
on an arm64 osx machine, or vice versa.

For this to work, an Objective C compiler needs to be set
in the Meson cross file.

vcpkg generates this file based on the
`scripts/buildsystems/meson/meson.template.in` template, and expects
the `MESON_OBJC` CMake variable to be set.

That's the job of `z_vcpkg_meson_set_proglist_variables` in
`scripts/cmake/vcpkg_configure_meson.cmake`.  It will only generate data
for an Objective C compiler if:

- The `Languages` argument includes `OBJC`
- CMake has detected a Objective C compiler, and has set `VCPKG_DETECTED_CMAKE_OBJC_COMPILER`

To make this work, this patch:
- Enables the OBJC and OBJCXX language on Apple platforms
- Updates the call to `vcpkg_configure_meson` in the glib port file
  to include the OBJC OBJCXX languages.

Fixes microsoft#26147
Fixes microsoft#20341
Based on microsoft#26259
Based on TechSmith@27dee35

Tested on an arm64 mac to compile glib for x64 macos
@qmfrederik
Copy link
Contributor Author

@Neumann-A Thank you for your feedback! I was able to simplify the PR a bit, and confirmed it works on my M2 Mac when cross-compiling for x64 Mac (something which fails without this patch)

@qmfrederik qmfrederik changed the title Support cross-compiling Objective C code using Meson [glib] Support cross-compiling Objective C code using Meson Aug 23, 2023
@jimwang118 jimwang118 added the info:reviewed Pull Request changes follow basic guidelines label Aug 25, 2023
@dan-shaw dan-shaw merged commit ba58a3f into microsoft:master Aug 25, 2023
15 checks passed
@qmfrederik qmfrederik deleted the fixes/glib-macos-cross branch August 25, 2023 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist info:reviewed Pull Request changes follow basic guidelines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Meson build is missing ObjectiveC support [glib]:arm64-osx build failure
4 participants