Skip to content

Expand Makefile build to support MacOS#221

Merged
attipaci merged 1 commit into
Sigmyne:mainfrom
activexray:build_macos
Sep 2, 2025
Merged

Expand Makefile build to support MacOS#221
attipaci merged 1 commit into
Sigmyne:mainfrom
activexray:build_macos

Conversation

@activexray

@activexray activexray commented Aug 29, 2025

Copy link
Copy Markdown
Contributor

Fixes #220

  • Replaces all .so with an extension that dynamically is detected via uname
  • Replaces instances of LD_LIBRARY_PATH with one that dynamically changes to DYLD_LIBRARY_PATH for mac
  • Removed -D in the installation section, as mac's install doesn't support it. I think this is ok because we precede them with install -d, which is supported.
  • Updates CI tooling to build/test/install on MacOS
  • Update sed calls to work cross-platform in tests
  • Adjust CI install tests to install to a non-system directory (as you can't so so on MacOS)

@codecov

codecov Bot commented Aug 29, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.89%. Comparing base (635cb9f) to head (915b7ce).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #221   +/-   ##
=======================================
  Coverage   99.89%   99.89%           
=======================================
  Files          24       24           
  Lines        4690     4690           
  Branches      878      878           
=======================================
  Hits         4685     4685           
  Partials        5        5           
Flag Coverage Δ
unittests 99.89% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 635cb9f...915b7ce. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@activexray activexray force-pushed the build_macos branch 5 times, most recently from a5d0e9c to 8e75ba2 Compare August 29, 2025 19:53
@attipaci

attipaci commented Aug 29, 2025

Copy link
Copy Markdown
Collaborator

It's OK to drop solsys2.$(SOEXT) from the Mac OS build. It's another legacy module that needs a custom fortran adapter to work. If someone really wants that, they can work it out how to build it themselves together with their own fortran code...

@activexray

Copy link
Copy Markdown
Contributor Author

Ok! I'll get back at this after lunch haha

@attipaci

attipaci commented Aug 29, 2025

Copy link
Copy Markdown
Collaborator

Looks pretty promising so far. Nice quick work! I'm impressed. ;-)

@activexray

Copy link
Copy Markdown
Contributor Author

By the way, I went into the config and explicitly set the BUILTIN_SOLSYS2 ?= 0. I think the likes of that ifneq ($(BUILTIN_SOLSYS2),1) won't work properly if those variables are undefined because in make "" != 1is true. Why the linux build isn't trying to make the solsys2.so I have yet to figure out.

@attipaci

attipaci commented Aug 29, 2025

Copy link
Copy Markdown
Collaborator

I suggest to put l.65 in the Makefile:

  SHARED_TARGETS += $(LIB)/libsolsys2.$(SOEXT)

inside a nested conditional, probably for Darwin (because I think it another Mac OS quirk). E.g.:

ifneq ($(BUILTIN_SOLSYS2),1)
  SOLSYS_TARGETS += $(OBJ)/solsys2.o
  # Don't build solsys2 shared lib on Mac OS -- it does not like mystery symbols.
  ifneq ($(shell uname -s),Darwin)
    SHARED_TARGETS += $(LIB)/libsolsys2.$(SOEXT)
  endif
endif

@attipaci

attipaci commented Aug 29, 2025

Copy link
Copy Markdown
Collaborator

By the way, I went into the config and explicitly set the BUILTIN_SOLSYS2 ?= 0. I think the likes of that ifneq ($(BUILTIN_SOLSYS2),1) won't work properly if those variables are undefined because in make "" != 1is true. Why the linux build isn't trying to make the solsys2.so I have yet to figure out.

The point is that when solsys2 is not built-in then it is provided separately, as a .o object and a libsolsys2.so library -- either which can be linked against on demand, as needed. Built-in means that it is an integral part of libsupernovas.so. We only want that for solsys3 and not the others...

It looks like that for the Mac OS build you don't want to deal with solsys2 either way (neither built in, not shared lib), although the .o object could still be built... I also checked clang on Linux, and it does not bark. So it's another Mac OS quirk. I'll revise the above suggestion accordingly...

@activexray

Copy link
Copy Markdown
Contributor Author

Makes sense! Boy do I love platform-specific quirks.

@activexray

Copy link
Copy Markdown
Contributor Author

sigh mac's sed is not the same sed.

@attipaci

Copy link
Copy Markdown
Collaborator

sigh mac's sed is not the same sed.

of course....

@activexray activexray changed the title [WIP] Expand Make build to support MacOS [WIP] Expand build to support MacOS Aug 29, 2025
@activexray

Copy link
Copy Markdown
Contributor Author

Oops I broke in install ci

@attipaci

attipaci commented Aug 29, 2025

Copy link
Copy Markdown
Collaborator

It looks like the libsolsys*.$(SOEXT).$(SO_VERSION) build needs an explicit LD_LIBRARY_PATH (or DYLD_LIBRARY_PATH for MacOS) pointing to the lib/ directory... (so it can link against the so, before it's installed in the standard location after the build).

I think you want to add that to Makefile at:

$(LIB)/libsolsys%.so.$(SO_VERSION): | $(LIB) $(LIB)/libsupernovas.so
	$(CC) -o $@ $(SOFLAGS) -L$(LIB) -lsupernovas $(SHLIBS)

You probaly need an ifeq / else / endif to set it differently for Darwin like in make benchmark...

@activexray activexray force-pushed the build_macos branch 5 times, most recently from fb2f99d to 02f5784 Compare August 29, 2025 22:11
@activexray activexray force-pushed the build_macos branch 8 times, most recently from a82557d to ca6f91e Compare August 29, 2025 22:51
@activexray activexray marked this pull request as ready for review August 29, 2025 22:51
@activexray activexray changed the title [WIP] Expand build to support MacOS Expand build to support MacOS Aug 29, 2025
@activexray

Copy link
Copy Markdown
Contributor Author

Alright @attipaci give this a look. I'm not super satisfied with checking the platform in three places, but I couldn't figure out a pattern to make it work right once.

@activexray

Copy link
Copy Markdown
Contributor Author

I'm drafting up a CMake alternative too - just to sus it out a bit.

@attipaci

Copy link
Copy Markdown
Collaborator

Thanks for all the effort. I'll look at it tomorrow, and see if I have any further ideas for improvement...

@attipaci attipaci self-requested a review August 29, 2025 23:22

@attipaci attipaci left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Kiran, thanks for all the work you put into it. It looks pretty good. I just have a few minor comments. Take them lightly, and ignore them if you don't agree. ;-)

Comment thread Makefile Outdated
$(LIB)/libsolsys%.$(SOEXT).$(SO_VERSION): | $(LIB) $(LIB)/libsupernovas.$(SOEXT).$(SO_VERSION)
ifeq ($(UNAME_S),Darwin)
$(CC) -o $@ $(CPPFLAGS) $(CFLAGS) $^ \
-dynamiclib -fPIC \

@attipaci attipaci Aug 29, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One thing we could try is to define SOFLAGS (or whatever) in config.mk e.g. as:

ifeq ($(UNAME_S),Darwin)
  SOFLAGS = -dynamiclib -fPIC -Wl,-install_name,@rpath/$(notdir $@)
else
  SOFLAGS = -shared -fPIC -Wl,-soname,$(notdir $@)
endif

and then have a simple rule here (and elsewhere as):

/libsolsys%.$(SOEXT).$(SO_VERSION): | $(LIB) $(LIB)/libsupernovas.$(SOEXT).$(SO_VERSION)
        $(CC) -o $@ $(CPPFLAGS) $(CFLAGS) $^ $(SOFLAGS) $(LIB)/libsupernovas.$(SOEXT).$(SO_VERSION) $(SHLIBS) $(LDFLAGS)

I think the explicit specification of the libsupernovas.so to link against is a good idea regardless of whether it's MacOS or not. I'm not sure that the .$(SO_VERSION) is needed though when invoking libsupernovas. My guess is that part can be omitted...

Of course including the $@ in the SOFLAGS definition might not work but it's worth a try, and maybe there is something similar than can work even if it not exactly the same as proposed...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I had a lot of problems with $@ not being in a specific recipe. I think I might have a solution, testing now.

- os: ubuntu-latest
cc: gcc
- os: macos-latest
cc: clang

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Apart from adding macos to the CI, I like the clang here for other reasons also. I was already thinking to add clang builds to the CI, so there it is. Done. Thanks! :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It isn't fully matrix'ed though. I'ts only mapping gcc to ubuntu and clang to macos. We can add cc to the matrix to get all four combinations though!

Comment thread config.mk Outdated
Comment thread config.mk
@attipaci attipaci added the enhancement New feature or request label Aug 30, 2025
@attipaci attipaci added this to the 1.5.0 milestone Aug 30, 2025
@activexray activexray changed the title Expand build to support MacOS Expand Makefile build to support MacOS Aug 31, 2025
@activexray activexray force-pushed the build_macos branch 2 times, most recently from 1d0b547 to f759c76 Compare August 31, 2025 19:29
@activexray

Copy link
Copy Markdown
Contributor Author

Alright I've cleaned up the logic quite a bit and consolidated the platform-specifics in one place in config.mk.

@attipaci attipaci merged commit a1aac1f into Sigmyne:main Sep 2, 2025
17 checks passed
@attipaci

attipaci commented Sep 3, 2025

Copy link
Copy Markdown
Collaborator

It turns out that this broke the shared libs build for Linux packaging. A fix is at PR #226. Generally, one should not set rpath when building the shared lib itself, especially not to a local directory that is not the final install location of the shared library. Instead, if you want to link a local shared library, you need to use the -L flag to tell the linker where (else) to look for shared libraries outside of the usual locations.

rpath probably need not be set in CMakeLists.txt either. For example, CALCEPH does not set CMAKE_INSTALL_RPATH... (PR #227)

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build for MacOS

2 participants