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

MACOSX: Add dynamic plugin support to macOS bundles #3877

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

dwatteau
Copy link
Contributor

@dwatteau dwatteau commented May 14, 2022

This PR lets one build and run a macOS Bundle (= ScummVM.app) with dynamic plugins for the game engines.

I'm doing this to resurrect the Mac PowerPC port, where the old PowerPC linker can't cope with a single static ScummVM binary with all engines anymore (and Mach-O doesn't offer as many flags as ELF to work around this).

This is split into several smaller commits:

  • split OSystem_MacOSX::addSysArchivesToSearchSet() so that we now have a separate getResourceAppBundlePathMacOSX() wrapper (so that both the shader and plugin loading code can use it).
  • let macOS have its own addCustomDirectories() (like the Nintendo DS port does), so that plugins can be loaded from the current macOS bundle if it exists.
  • use strip -x to strip the main scummvm binary when building plugins, in order to keep global symbols (otherwise the plugins will fail loading).
  • use the $(PRE_OBJS_FLAGS) variable (i.e. -all_load) when linking scummvm-static, otherwise it will fail loading its dynamic plugins, too.
  • let ports.mk install plugins to Contents/Resources/ in the bundle, when dynamic plugins are enabled.

It should have no impact on default macOS Intel/ARM builds, which don't use dynamic plugins by default at the moment.

However, I don't have a lot of experience with macOS bundles and plugins, so I hope I'm not doing any big mistake here.

Tested on Tiger (which needs a couple of build fixes that I've put into PR #3878) and Monterey.

@raziel-
Copy link
Contributor

@raziel- raziel- commented May 14, 2022

Oh sweet.
Another PPC platform with plugins...I might ask for help with plugin problems in the future, if I may?

@dwatteau
Copy link
Contributor Author

@dwatteau dwatteau commented May 14, 2022

Oh sweet.
Another PPC platform with plugins...I might ask for help with plugin problems in the future, if I may?

@raziel- Yeah of course, but I'm afraid I have no real knowledge in loading plugins on AmigaOS if that's your goal. Most of the hard work for Mac PPC and dynamic plugins on macOS was already there for a long time, here I'm just doing the final assembly ;)

@raziel-
Copy link
Contributor

@raziel- raziel- commented May 14, 2022

Heh, no problem.
@lephilousophe already helped finding and fixing a long standing bug in my platforms gcc/toolchain, which preventing using dynamic plugins in scummvm, so that's settled.

And I already read through your changes and will try the 'strip -x' approach to see if it fixes some shared build oddities for me.

So, you already helped :-)

raziel- added a commit to raziel-/scummvm that referenced this issue May 15, 2022
@BeWorld2018

- Change plugin naming
- Add using dl library for dynamic
- Add "x" flag for strip to preserve global symbols with dynamic (honestly stolen from @dwatteau and scummvm#3877) ;-)

I'd like to get your confirmation on this, since it also touches MorphOS.
Otherwise i'll have to split targets.

Conforming to many of the other platforms use of plugin naming
and to distinguish between ScummVM's engine plugins and the OS'
shared objects/libraries names.
@criezy
Copy link
Member

@criezy criezy commented May 16, 2022

Great! Adding support for dynamic plugins is I think the correct way to go to resurrect the PPC port due to the executable size limitations. That could maybe also be of interest for more recent macOS versions, even if not required. Something else that could have helped as well and that I wanted to look at is to use dynamic libraries rather than static ones for the bundles.

I will need a bit more time to review the actual changes, but this seems to go in the right direction.

Copy link
Member

@criezy criezy left a comment

Great work! I have suggested a couple of changes which I think would be good, but otherwise this is in good shape and ready to merge.

And a bit of nitpicking for the commit message prefixes:

  • It would also be good to use MACOSX instead of MACOS for e5952c0 for consistency.
  • And it may be better to use BUILD for 95c8ae0.

backends/plugins/sdl/sdl-provider.cpp Outdated Show resolved Hide resolved
@dwatteau dwatteau force-pushed the feat/macos-plugin-support-in-bundle branch 2 times, most recently from ad6bf69 to d62e268 Compare May 18, 2022
@dwatteau dwatteau changed the title MACOS: Add dynamic plugin support to macOS bundles MACOSX: Add dynamic plugin support to macOS bundles May 18, 2022
dwatteau added 5 commits May 18, 2022
…y on macOS

Global symbols should be kept when building dylibs.
Otherwise, making a macOS bundle with plugins wouldn't load any of
these plugins (i.e. -all_load is required).
As suggested by criezy, we don't need to use the C-bridge from Core
Foundation now that the wrapper has been moved to an Objective-C file.
@dwatteau dwatteau force-pushed the feat/macos-plugin-support-in-bundle branch from d62e268 to e6bd6e8 Compare May 18, 2022
@dwatteau dwatteau requested a review from criezy May 18, 2022
bluegr pushed a commit that referenced this issue May 21, 2022
@BeWorld2018

- Change plugin naming
- Add using dl library for dynamic
- Add "x" flag for strip to preserve global symbols with dynamic (honestly stolen from @dwatteau and #3877) ;-)

I'd like to get your confirmation on this, since it also touches MorphOS.
Otherwise i'll have to split targets.

Conforming to many of the other platforms use of plugin naming
and to distinguish between ScummVM's engine plugins and the OS'
shared objects/libraries names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants