-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[RFC] meson: support exporting to xcode #12235
base: master
Are you sure you want to change the base?
Conversation
Meson cannot handle object-only executables or libraries with the Xcode backend, so compile them from source.
Xcode supports mixing Swift with other C languages through bridging and interface headers, so we can just define those.
libmpv and mpv will have different interface header names by default, and having sources compiled twice is unnecessary. To fix this, only compile the main function file for mpv and link it to libmpv.
Marked this as draft for now since it depends on some meson changes. |
Can this pull request continue to be processed? Building with Xcode can significantly enhance the debugging experience on macOS. |
i am not completely against any kinda of xcode integration, i made a similar PR #8854 once. building was completely done via meson still and you could debug via xcode. though not sure this is the right way to go:
maybe it would just be better to add/write a tutorial how to create an xcode project that uses our build system instead, eg how i created the my previous PR. |
I personally enjoy using Xcode for debugging because it makes tracking variables in frames and threads much more convenient, especially compared to use lldb in command line. Even Xcode supports debugging through attach to a runtime process, some advanced features are disabled. I've seen a project(https://github.com/libobjc/FFmpeg-in-Xcode) for ffmpeg, but I'm not sure if we could achieve something similar. I'm happy to spend time on this work, writing a tutorial, or creating a similar project, but it won’t be immediately as I’m currently quite busy. |
@Akemi I understand some of your concerns, and I read through your old PR when I was working on this one. Let me clear up some of your concerns and explain what I was thinking when I was working on this.
In this PR, both of those things are avoided. Meson is able to export to Xcode, and when it does, the generated project file forces Xcode to use the Meson build system. Meson still uses ninja as the default backend, so the only time Xcode is required is if the user specifies it as the backend during setup.
I think this is in reference to your old PR. I can see how that would be a burden, considering what it took for you to even make the project file in the first place. One of my goals for this PR was to avoid that entirely, since Meson can just generate that project file instead. Plus, I don't think anyone wants to deal with merge conflicts taking place in that file every time they update their fork.
For the most part, I tried to minimize this as much as possible, since Meson's Xcode backend works much better now and is getting a bit more attention than it did before. That being said, there are some things that Xcode cannot handle due to its own limitations (e.g. it can't handle object-only targets), so if there is any of that added build complexity, it's mainly to address that problem. It should have absolutely no effect when Xcode is not being used as the backend by Meson. If there is anything I have missed, please feel free to let me know and I can address it. |
the whole swift compilation/target is excluded (https://github.com/mpv-player/mpv/pull/12235/files#diff-b72cb4b6ee70aeec879fdbd428279f1e80b0795137e185a144673a172bebbef0R39-R66), so who takes care of this? it's not our code so it's either something from meson or xcode. in either case it's another build path that i would possibly avoid. it makes the whole thing more complex and adds another opening for errors (mentioned above). if it's meson, we should use this functionality not just for exporting to xcode but get rid of our whole custom target.
no, see above. if possible:
otherwise i would be fine going forward with this. |
I think I understand what you mean this time, so I'll explain it this way: The entire project can be exported to Xcode in its current state, but it won't build successfully because of linking errors. To address that problem, you only need to do this: @@ -1816,8 +1815,8 @@ if get_option('cplayer')
rename: 'mpv.svg')
install_data('etc/mpv-symbolic.svg', install_dir: join_paths(hicolor_dir, 'symbolic', 'apps'))
- mpv = executable('mpv', main_fn_source, objects: libmpv.extract_all_objects(recursive: true), dependencies: dependencies,
- win_subsystem: get_option('win32-subsystem'), install: true)
+ mpv = executable('mpv', main_fn_source, dependencies: dependencies,
+ win_subsystem: get_option('win32-subsystem'), install: true, link_with: libmpv)
if win32 and get_option('win32-subsystem') != 'console'
wrapper_sources= 'osdep/win32-console-wrapper.c' That's all you actually have to do so you can start debugging this in Xcode. Replacing The other changes, I can explain. A few of them aren't needed anymore because they have already been addressed in one way or another, but the one you're concerned about has a decent explanation.
When using Xcode as the backend, the custom swift target is excluded because its sources are added into the libmpv target instead (https://github.com/mpv-player/mpv/pull/12235/files#diff-30d8f6be6320feeacf686be94f48c70869b52630e01ea625f0f15adc0d57c3e4R1579-R1586). The idea is to make those files visible to Xcode, since meson doesn't add input files in custom targets to Xcode at all. Xcode can already do what the custom target is configured to do anyway, but it generates the bridge header file in a different place, so I ended up doing stuff like more preprocessing just so it compiles. It's not an ideal way to handle it, but at least it works. It's not a necessary change if you're not concerned about being able to edit those swift files in Xcode. It just makes development a bit easier when you have to make changes there.
I'm guessing you want to turn that into a library target that libmpv links to, right? That would be beyond the scope of this PR, but it is something worth doing because the custom target looks like a workaround. |
Even though Meson supports exporting to Xcode, a few changes are required so that mpv runs successfully on it:
Right now, Meson's Xcode backend is in need of repairs (see mesonbuild#12056). At best, mpv will not be able to take advantage of this until Meson 1.3.0 is released.Meson's Xcode backend is functional as of 1.4.0, so mpv can take advantage of this now.