Skip to content

Commit

Permalink
Update tccmacho.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Sep 17, 2024
1 parent d5c6034 commit 75b71c9
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions tccmacho.c
Original file line number Diff line number Diff line change
Expand Up @@ -2299,18 +2299,34 @@ ST_FUNC char* tcc_search_darwin_framework(TCCState* s, const char* include_name)
#endif

ST_FUNC void tcc_add_macos_framework_path(TCCState* s, const char* framework_name, const char* base_path) {
// if this is a system framework, we need to add it via /System/Library/Frameworks/
char path_buffer[2048];
pstrcpy(path_buffer, sizeof(path_buffer), base_path);
pstrcat(path_buffer, sizeof(path_buffer), "/System/Library/Frameworks/");
pstrcat(path_buffer, sizeof(path_buffer), framework_name);
pstrcat(path_buffer, sizeof(path_buffer), ".framework/");
// .tbd
pstrcat(path_buffer, sizeof(path_buffer), "Versions/Current/");
pstrcat(path_buffer, sizeof(path_buffer), framework_name);
pstrcat(path_buffer, sizeof(path_buffer), ".tbd");
tcc_add_library_path(s, path_buffer);

// .framework/Headers
// Keep it loaded, but only once.
void *handle = dlopen(path_buffer, RTLD_GLOBAL | RTLD_LAZY | RTLD_NOLOAD);
if (handle) {
dlclose(handle);
} else {
handle = dlopen(path_buffer, RTLD_GLOBAL | RTLD_LAZY);
}

if (!handle) {
pstrcpy(path_buffer, sizeof(path_buffer), base_path);
pstrcat(path_buffer, sizeof(path_buffer), "/System/Library/Frameworks/");
pstrcat(path_buffer, sizeof(path_buffer), framework_name);
pstrcat(path_buffer, sizeof(path_buffer), ".framework/");
// .tbd
pstrcat(path_buffer, sizeof(path_buffer), "Versions/Versions/A/");
pstrcat(path_buffer, sizeof(path_buffer), framework_name);
pstrcat(path_buffer, sizeof(path_buffer), ".tbd");
tcc_add_library_path(s, path_buffer);
}

// The system frameworks don't include headers, so we need to add them separately
pstrcpy(path_buffer, sizeof(path_buffer), base_path);
pstrcat(path_buffer, sizeof(path_buffer), "/System/Library/Frameworks/");
pstrcat(path_buffer, sizeof(path_buffer), framework_name);
Expand Down

0 comments on commit 75b71c9

Please sign in to comment.