Skip to content

Conversation

@thatcomputerguy0101
Copy link

@thatcomputerguy0101 thatcomputerguy0101 commented Nov 26, 2025

This updates the build scripts and fixes a few minor incompatibilities to add macOS support. The macOS build uses a universal binary to reduce the number of distribution artifacts. This replaces malloc.h with stdlib.h, adds matching for macOS libraries, and links to Accelerate for BLAS support. The double *. in the dependency library glob prevents matching the libopencv_java bundle dylib which cannot be loaded via fetchcontent.

@thatcomputerguy0101
Copy link
Author

MacOS still needs added to the build workflow.

@thatcomputerguy0101 thatcomputerguy0101 marked this pull request as draft November 26, 2025 21:06
@mcm001
Copy link
Collaborator

mcm001 commented Nov 26, 2025

Can/should we be building universal binaries?

@thatcomputerguy0101
Copy link
Author

I added additional targets for macOS to the build action. I was going to try to get both targets to build on the Arm runner, but I was encountering a problem where the OpenCV arch got dropped if I tried to change the complier target.

@thatcomputerguy0101
Copy link
Author

Can/should we be building universal binaries?

Maybe? I didn't try that yet.

@thatcomputerguy0101
Copy link
Author

Building a universal binary seemed to work, which yields fewer artifacts to distribute.

@thatcomputerguy0101 thatcomputerguy0101 force-pushed the macos branch 2 times, most recently from 596ffc6 to 3515ed3 Compare November 27, 2025 04:48
@thatcomputerguy0101 thatcomputerguy0101 marked this pull request as ready for review November 27, 2025 04:58
@thatcomputerguy0101
Copy link
Author

It seems like OpenBLAS may not be easy to compile a universal binary for. (I haven't eliminated the possibility yet though.)

@spacey-sooty
Copy link
Member

Can we not link to Accelerate?

@thatcomputerguy0101
Copy link
Author

thatcomputerguy0101 commented Nov 29, 2025

Prior to macOS 26, Accelerate is 32-bit only. I only confirmed it passes the PV tests on macOS 26.

@Gold856
Copy link
Contributor

Gold856 commented Dec 5, 2025

To be honest, I think we use a 32 bit BLAS everywhere. I believe OpenBLAS is built with the LP64 API, so I think it's fine? And if it works with the ILP64 API, then I guess that's also fine?

Copy link
Contributor

@Gold856 Gold856 left a comment

Choose a reason for hiding this comment

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

I'm gonna block only because I want a vanilla mrcal.

@thatcomputerguy0101
Copy link
Author

I tested this again with mrcal 2.5 from #17, and had it working. A few corrections from my previous messages, Apple Accelerate was actually updated with ILP64 support in macOS 13.3, not macOS 26. There were other version updates since then, and Apple's documentation only mentions the most recent one. PhotonVision tests still passed with both compile definitions removed, but I think it may still be good to leave the ACCERATE_NEW_LAPACK definition enabled. (I don't really know what either definition is doing though.)

@thatcomputerguy0101
Copy link
Author

When I updated the Gradle scripts, I only replaced the arm64 build with the universal build. Any other architectures will remain unchanged.

@thatcomputerguy0101 thatcomputerguy0101 changed the title Add MacOS support Add macOS support Dec 28, 2025
Copy link
Collaborator

@mcm001 mcm001 left a comment

Choose a reason for hiding this comment

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

Looks like a green pipeline to me!

@thatcomputerguy0101
Copy link
Author

I wasn't building mrcal_jni_test before. That is still broken.

@thatcomputerguy0101
Copy link
Author

vnlog seems to be incompatible with macOS due to its use of tdestroy, which doesn't exist there. Is it better to just skip trying to build the tests on macOS for now?

@Gold856
Copy link
Contributor

Gold856 commented Dec 29, 2025

Seems like <search.h> is part of the POSIX standard, not the C standard. See if invoking Apple Clang manually with -D_POSIX_C_SOURCE=200809L and compiling this test file will work:

#include <search.h>

If it does, use add_compile_definitions to add that define into the CMake build.

@thatcomputerguy0101
Copy link
Author

thatcomputerguy0101 commented Dec 29, 2025

This is the search.h VSCode finds on macOS 26:

/*-
 * Written by J.T. Conklin <jtc@netbsd.org>
 * Public domain.
 *
 *	$NetBSD: search.h,v 1.12 1999/02/22 10:34:28 christos Exp $
 * $FreeBSD: src/include/search.h,v 1.10 2002/10/16 14:29:23 robert Exp $
 */

#ifndef _SEARCH_H_
#define _SEARCH_H_

#include <sys/cdefs.h>
#include <_bounds.h>
#include <_types.h>
#include <sys/_types/_size_t.h>

_LIBC_SINGLE_BY_DEFAULT()

typedef	struct entry {
	char *_LIBC_CSTR	key;
	void	*data;
} ENTRY;

typedef	enum {
	FIND, ENTER
} ACTION;

typedef	enum {
	preorder,
	postorder,
	endorder,
	leaf
} VISIT;

#ifdef _SEARCH_PRIVATE
typedef	struct node {
	char *_LIBC_CSTR	key;
	struct node  *llink, *rlink;
} node_t;

struct que_elem {
	struct que_elem *next;
	struct que_elem *prev;
};
#endif

__BEGIN_DECLS
int	 hcreate(size_t);
void	 hdestroy(void);
ENTRY	*hsearch(ENTRY, ACTION);
void	 insque(void *, void *);
void	*lfind(const void *, const void *_LIBC_UNSAFE_INDEXABLE, size_t *, size_t,
	    int (*)(const void *, const void *));
void	*lsearch(const void *, void *, size_t *_LIBC_UNSAFE_INDEXABLE, size_t,
	    int (*)(const void *, const void *));
void	 remque(void *);
void	*tdelete(const void * __restrict, void ** __restrict,
	    int (*)(const void *, const void *));
void	*tfind(const void *, void * const *,
	    int (*)(const void *, const void *));
void	*tsearch(const void *, void **, int (*)(const void *, const void *));
void	 twalk(const void *, void (*)(const void *, VISIT, int));
__END_DECLS

#endif /* !_SEARCH_H_ */

Maybe twalk could be used to replace tdestroy?

@thatcomputerguy0101
Copy link
Author

I found this (POSIX?) documentation with an example of how to delete all nodes of a tree without tdestroy. I guess I'll PR that to vnlog.

@Gold856
Copy link
Contributor

Gold856 commented Dec 29, 2025

Yeah, that's probably the move. I just reread some documentation and somehow missed that tdestroy is actually a GNU extension of search.h.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants