Skip to content

Commit 8c3c1e4

Browse files
committed
Special-case loading libraries from Homebrew.
1 parent 7e384e1 commit 8c3c1e4

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/_raqm.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ ITER_RAQM_API(DEFINE_API)
2020
bool bad_color_glyph_spacing{};
2121
decltype(hb::version_string) hb::version_string{};
2222

23-
void load_raqm() {
23+
void load_raqm()
24+
{
2425
if (!raqm::_handle) {
2526
char const* filename =
2627
#if defined __linux__
@@ -32,7 +33,19 @@ void load_raqm() {
3233
#endif
3334
raqm::_handle = os::dlopen(filename);
3435
if (!raqm::_handle) {
35-
os::throw_dlerror();
36+
#if defined __APPLE__
37+
// Homebrew doesn't add itself to the library loader path, but we can
38+
// detect that case: if FreeType comes from Homebrew (this typically
39+
// depends on how cairo/pycairo were installed), then also try to load
40+
// raqm from Homebrew.
41+
auto ft_path = os::dladdr_fname(FT_Library_Version);
42+
if (ft_path.find("/opt/homebrew/") == 0) {
43+
raqm::_handle = os::dlopen("/opt/homebrew/lib/libraqm.dylib");
44+
}
45+
#endif
46+
if (!raqm::_handle) {
47+
os::throw_dlerror();
48+
}
3649
}
3750
#define LOAD_API(name) \
3851
if (!(raqm::name = os::dlsym(raqm::_handle, "raqm_" #name))) { \
@@ -58,7 +71,8 @@ void load_raqm() {
5871
}
5972
}
6073

61-
void unload_raqm() {
74+
void unload_raqm()
75+
{
6276
if (raqm::_handle) {
6377
auto const& error = os::dlclose(raqm::_handle);
6478
raqm::_handle = nullptr;
@@ -68,7 +82,8 @@ void unload_raqm() {
6882
}
6983
}
7084

71-
bool has_raqm() {
85+
bool has_raqm()
86+
{
7287
return raqm::_handle;
7388
}
7489

0 commit comments

Comments
 (0)