Skip to content

Commit f24a2e1

Browse files
committed
fix: more platform support
1 parent 7d8574b commit f24a2e1

File tree

2 files changed

+47
-67
lines changed

2 files changed

+47
-67
lines changed

include/platform_compat.h

Lines changed: 44 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,62 @@
1-
#ifndef PLATFORM_COMPAT_H
2-
#define PLATFORM_COMPAT_H
3-
4-
#ifndef _GNU_SOURCE
5-
#define _GNU_SOURCE
6-
#endif
7-
8-
#ifndef _POSIX_C_SOURCE
9-
#define _POSIX_C_SOURCE 200809L
10-
#endif
1+
#pragma once
112

3+
/* ===================== PLATFORM DETECTION ===================== */
124
#ifdef _WIN32
13-
#include <direct.h>
14-
#define strncasecmp _strnicmp
15-
#define strcasecmp _stricmp
5+
#define PLATFORM_WINDOWS 1
6+
#else
7+
#define PLATFORM_WINDOWS 0
168
#endif
179

1810
#ifdef __APPLE__
19-
#include <strings.h> // for strncasecmp, strcasecmp
20-
#include <sys/types.h>
21-
#include <sys/sysctl.h>
22-
#endif
23-
24-
#include "mupdf/fitz.h"
25-
26-
#ifndef FZ_STEXT_CLIP
27-
#define FZ_STEXT_CLIP 1
28-
#endif
29-
30-
#ifndef FZ_STEXT_ACCURATE_BBOXES
31-
#define FZ_STEXT_ACCURATE_BBOXES 2
32-
#endif
33-
34-
#ifndef FZ_STEXT_COLLECT_STYLES
35-
#define FZ_STEXT_COLLECT_STYLES 32768
36-
#endif
37-
38-
#ifndef FZ_STEXT_USE_GID_FOR_UNKNOWN_UNICODE
39-
#define FZ_STEXT_USE_GID_FOR_UNKNOWN_UNICODE 4
40-
#endif
41-
42-
#ifndef FZ_STEXT_PRESERVE_LIGATURES
43-
#define FZ_STEXT_PRESERVE_LIGATURES 8
44-
#endif
45-
46-
#ifndef FZ_STEXT_PRESERVE_WHITESPACE
47-
#define FZ_STEXT_PRESERVE_WHITESPACE 16
48-
#endif
49-
50-
#ifndef FZ_FONT_FLAG_BOLD
51-
#define FZ_FONT_FLAG_BOLD 1
11+
#define PLATFORM_MAC 1
12+
#include <TargetConditionals.h>
13+
#else
14+
#define PLATFORM_MAC 0
5215
#endif
5316

54-
#ifndef FZ_FONT_FLAG_ITALIC
55-
#define FZ_FONT_FLAG_ITALIC 2
17+
#ifdef __linux__
18+
#define PLATFORM_LINUX 1
19+
#else
20+
#define PLATFORM_LINUX 0
5621
#endif
5722

23+
/* ===================== EXPORT MACRO ===================== */
24+
#ifndef EXPORT
5825
#ifdef _WIN32
5926
#define EXPORT __declspec(dllexport)
6027
#else
61-
#define EXPORT __attribute__((visibility("default")))
28+
#define EXPORT
29+
#endif
6230
#endif
6331

64-
/* --- Added CPU detection helper for multiprocess --- */
65-
static inline int get_num_cores(void)
66-
{
67-
int num_cores = 1;
32+
/* ===================== LEGACY TYPE FIXES FOR MAC ===================== */
33+
#if PLATFORM_MAC
34+
typedef unsigned int u_int;
35+
typedef unsigned char u_char;
36+
typedef unsigned short u_short;
6837

69-
#if defined(_SC_NPROCESSORS_ONLN)
70-
long n = sysconf(_SC_NPROCESSORS_ONLN);
71-
if (n > 0)
72-
num_cores = (int)n;
73-
#elif defined(__APPLE__)
74-
int n;
75-
size_t len = sizeof(n);
76-
int mib[2] = {CTL_HW, HW_AVAILCPU};
77-
if (sysctl(mib, 2, &n, &len, NULL, 0) == 0 && n > 0)
78-
num_cores = n;
38+
#include <unistd.h>
39+
#include <sys/types.h>
40+
#include <sys/sysctl.h>
41+
#include <strings.h>
42+
43+
/* get number of CPU cores */
44+
static int get_num_cores() {
45+
int nm[2];
46+
size_t len = sizeof(int);
47+
int count;
48+
nm[0] = CTL_HW;
49+
nm[1] = HW_NCPU;
50+
sysctl(nm, 2, &count, &len, NULL, 0);
51+
return count;
52+
}
7953
#endif
8054

81-
return num_cores;
82-
}
55+
/* ===================== MATH/UTILS ===================== */
56+
#include <math.h>
57+
#include <stdint.h>
58+
#include <stdbool.h>
8359

84-
#endif // PLATFORM_COMPAT_H
60+
#ifndef NAN
61+
#define NAN (__builtin_nanf("0x7fc00000"))
62+
#endif

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
44

55
[project]
66
name = "pymupdf4llm-c"
7-
version = "1.0.6"
7+
version = "1.1.0"
88
description = "C-backed PDF to Markdown conversion with Python fallbacks"
99
authors = [{ name = "PyMuPDF4LLM Contributors" }]
1010
readme = "README.md"
@@ -147,12 +147,14 @@ build = [
147147
"cp3{9,10,11,12,13}-manylinux_x86_64",
148148
"cp3{9,10,11,12,13}-macosx_arm64"
149149
] # linux x64 and macOS arm64 only (3.9->3.13)
150+
before-build = "rm -f lib/mupdf/*.so lib/mupdf/*.so.* lib/mupdf/*.dylib 2>/dev/null || true" # cibuildwheel complains
150151

151152
# ---------------------------------------------------------
152153
# Linux Specifics
153154
# ---------------------------------------------------------
154155
[tool.cibuildwheel.linux]
155156
environment = { LD_LIBRARY_PATH = "$PWD/lib/mupdf" }
157+
repair-wheel-command = "auditwheel repair -w {dest_dir} {wheel}"
156158

157159
# ---------------------------------------------------------
158160
# macOS Specifics

0 commit comments

Comments
 (0)