objcjs-types 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/objcjs-types.ts +31 -0
- package/dist/AVFoundation/functions.d.ts +21 -0
- package/dist/AVFoundation/functions.js +32 -0
- package/dist/Accessibility/functions.d.ts +16 -0
- package/dist/Accessibility/functions.js +35 -0
- package/dist/AddressBook/functions.d.ts +98 -0
- package/dist/AddressBook/functions.js +290 -0
- package/dist/AppKit/functions.d.ts +112 -0
- package/dist/AppKit/functions.js +272 -0
- package/dist/AudioToolbox/functions.d.ts +377 -0
- package/dist/AudioToolbox/functions.js +1124 -0
- package/dist/AuthenticationServices/functions.d.ts +2 -0
- package/dist/AuthenticationServices/functions.js +5 -0
- package/dist/BrowserEngineCore/functions.d.ts +3 -0
- package/dist/BrowserEngineCore/functions.js +11 -0
- package/dist/CoreAudio/functions.d.ts +60 -0
- package/dist/CoreAudio/functions.js +173 -0
- package/dist/CoreMIDI/functions.d.ts +96 -0
- package/dist/CoreMIDI/functions.js +287 -0
- package/dist/CoreML/functions.d.ts +2 -0
- package/dist/CoreML/functions.js +5 -0
- package/dist/CoreMediaIO/functions.d.ts +38 -0
- package/dist/CoreMediaIO/functions.js +107 -0
- package/dist/CoreText/functions.d.ts +209 -0
- package/dist/CoreText/functions.js +611 -0
- package/dist/CoreWLAN/functions.d.ts +23 -0
- package/dist/CoreWLAN/functions.js +56 -0
- package/dist/DeviceDiscoveryExtension/functions.d.ts +11 -0
- package/dist/DeviceDiscoveryExtension/functions.js +17 -0
- package/dist/DiscRecording/functions.d.ts +97 -0
- package/dist/DiscRecording/functions.js +290 -0
- package/dist/DiscRecordingUI/functions.d.ts +13 -0
- package/dist/DiscRecordingUI/functions.js +38 -0
- package/dist/ExceptionHandling/functions.d.ts +1 -0
- package/dist/ExceptionHandling/functions.js +5 -0
- package/dist/FSKit/functions.d.ts +4 -0
- package/dist/FSKit/functions.js +11 -0
- package/dist/Foundation/functions.d.ts +145 -0
- package/dist/Foundation/functions.js +386 -0
- package/dist/GLKit/functions.d.ts +51 -0
- package/dist/GLKit/functions.js +146 -0
- package/dist/GameController/functions.d.ts +18 -0
- package/dist/GameController/functions.js +44 -0
- package/dist/HealthKit/functions.d.ts +19 -0
- package/dist/HealthKit/functions.js +35 -0
- package/dist/IOSurface/functions.d.ts +53 -0
- package/dist/IOSurface/functions.js +155 -0
- package/dist/IOUSBHost/functions.d.ts +44 -0
- package/dist/IOUSBHost/functions.js +131 -0
- package/dist/InstantMessage/functions.d.ts +1 -0
- package/dist/InstantMessage/functions.js +5 -0
- package/dist/JavaRuntimeSupport/functions.d.ts +40 -0
- package/dist/JavaRuntimeSupport/functions.js +113 -0
- package/dist/JavaScriptCore/functions.d.ts +120 -0
- package/dist/JavaScriptCore/functions.js +359 -0
- package/dist/MLCompute/functions.d.ts +27 -0
- package/dist/MLCompute/functions.js +41 -0
- package/dist/MapKit/functions.d.ts +23 -0
- package/dist/MapKit/functions.js +56 -0
- package/dist/Matter/functions.d.ts +17 -0
- package/dist/Matter/functions.js +26 -0
- package/dist/MediaAccessibility/functions.d.ts +28 -0
- package/dist/MediaAccessibility/functions.js +83 -0
- package/dist/MediaPlayer/functions.d.ts +3 -0
- package/dist/MediaPlayer/functions.js +11 -0
- package/dist/Metal/functions.d.ts +14 -0
- package/dist/Metal/functions.js +26 -0
- package/dist/MetalKit/functions.d.ts +11 -0
- package/dist/MetalKit/functions.js +20 -0
- package/dist/MetalPerformanceShaders/functions.d.ts +7 -0
- package/dist/MetalPerformanceShaders/functions.js +14 -0
- package/dist/NearbyInteraction/functions.d.ts +3 -0
- package/dist/NearbyInteraction/functions.js +5 -0
- package/dist/ParavirtualizedGraphics/functions.d.ts +7 -0
- package/dist/ParavirtualizedGraphics/functions.js +14 -0
- package/dist/QuartzCore/functions.d.ts +19 -0
- package/dist/QuartzCore/functions.js +50 -0
- package/dist/SceneKit/functions.d.ts +17 -0
- package/dist/SceneKit/functions.js +38 -0
- package/dist/SensorKit/functions.d.ts +4 -0
- package/dist/SensorKit/functions.js +14 -0
- package/dist/ServiceManagement/functions.d.ts +7 -0
- package/dist/ServiceManagement/functions.js +20 -0
- package/dist/StoreKit/functions.d.ts +1 -0
- package/dist/StoreKit/functions.js +5 -0
- package/dist/VideoToolbox/functions.d.ts +81 -0
- package/dist/VideoToolbox/functions.js +236 -0
- package/dist/Vision/functions.d.ts +16 -0
- package/dist/Vision/functions.js +38 -0
- package/generator/ast-parser.ts +1368 -0
- package/generator/clang.ts +167 -0
- package/generator/custom.ts +936 -0
- package/generator/discover.ts +111 -0
- package/generator/emitter.ts +2020 -0
- package/generator/frameworks.ts +135 -0
- package/generator/index.ts +1334 -0
- package/generator/parse-worker.ts +263 -0
- package/generator/resolve-strings.ts +121 -0
- package/generator/struct-fields.ts +46 -0
- package/generator/templates/bind.ts +100 -0
- package/generator/templates/helpers.ts +70 -0
- package/generator/templates/nsdata.ts +97 -0
- package/generator/templates/osversion.ts +91 -0
- package/generator/type-mapper.ts +615 -0
- package/generator/worker-pool.ts +309 -0
- package/package.json +17 -4
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs clang to produce AST JSON dumps from Objective-C header files.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const SDK_PATH = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk";
|
|
6
|
+
|
|
7
|
+
export interface ClangASTNode {
|
|
8
|
+
id: string;
|
|
9
|
+
kind: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
mangledName?: string;
|
|
12
|
+
loc?: Record<string, unknown>;
|
|
13
|
+
range?: Record<string, unknown>;
|
|
14
|
+
inner?: ClangASTNode[];
|
|
15
|
+
// ObjCInterfaceDecl
|
|
16
|
+
super?: { id: string; kind: string; name: string };
|
|
17
|
+
protocols?: { id: string; kind: string; name: string }[];
|
|
18
|
+
// ObjCMethodDecl
|
|
19
|
+
instance?: boolean;
|
|
20
|
+
returnType?: { qualType: string; desugaredQualType?: string };
|
|
21
|
+
// ObjCPropertyDecl / VarDecl / EnumConstantDecl
|
|
22
|
+
type?: { qualType: string; desugaredQualType?: string; typeAliasDeclId?: string };
|
|
23
|
+
// ObjCCategoryDecl
|
|
24
|
+
interface?: { id: string; kind: string; name: string };
|
|
25
|
+
// ParmVarDecl
|
|
26
|
+
// type is reused
|
|
27
|
+
// Availability
|
|
28
|
+
availability?: unknown[];
|
|
29
|
+
// ObjCPropertyDecl attributes
|
|
30
|
+
readonly?: boolean;
|
|
31
|
+
readwrite?: boolean;
|
|
32
|
+
// For checking if implicit
|
|
33
|
+
isImplicit?: boolean;
|
|
34
|
+
// EnumDecl
|
|
35
|
+
fixedUnderlyingType?: { qualType: string; desugaredQualType?: string; typeAliasDeclId?: string };
|
|
36
|
+
previousDecl?: string;
|
|
37
|
+
// VarDecl
|
|
38
|
+
storageClass?: string;
|
|
39
|
+
// ConstantExpr
|
|
40
|
+
value?: string;
|
|
41
|
+
// FunctionDecl
|
|
42
|
+
variadic?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Node kinds we actually need from the AST (ObjC decls, enums, structs, typedefs, vars for string enums) */
|
|
46
|
+
const RELEVANT_KINDS = new Set([
|
|
47
|
+
"ObjCInterfaceDecl",
|
|
48
|
+
"ObjCCategoryDecl",
|
|
49
|
+
"ObjCProtocolDecl",
|
|
50
|
+
"EnumDecl",
|
|
51
|
+
"RecordDecl",
|
|
52
|
+
"TypedefDecl",
|
|
53
|
+
"VarDecl",
|
|
54
|
+
"FunctionDecl"
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Strip the top-level AST to only keep nodes we care about.
|
|
59
|
+
* The clang AST includes thousands of FunctionDecl, TypedefDecl for C stdlib,
|
|
60
|
+
* RecordDecl for POSIX structs, etc. that we never process. By pruning these
|
|
61
|
+
* immediately after JSON.parse, we allow GC to reclaim ~50-70% of the parsed
|
|
62
|
+
* AST memory.
|
|
63
|
+
*
|
|
64
|
+
* This mutates the AST in place for minimal allocation.
|
|
65
|
+
*/
|
|
66
|
+
function pruneAST(ast: ClangASTNode): ClangASTNode {
|
|
67
|
+
if (ast.inner) {
|
|
68
|
+
ast.inner = ast.inner.filter((node) => RELEVANT_KINDS.has(node.kind));
|
|
69
|
+
}
|
|
70
|
+
return ast;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Run clang on a header file and return the parsed AST JSON.
|
|
75
|
+
* Clang may exit with code 1 due to warnings but still produce valid AST JSON.
|
|
76
|
+
*/
|
|
77
|
+
export async function clangASTDump(headerPath: string): Promise<ClangASTNode> {
|
|
78
|
+
const proc = Bun.spawn(
|
|
79
|
+
[
|
|
80
|
+
"clang",
|
|
81
|
+
"-Xclang",
|
|
82
|
+
"-ast-dump=json",
|
|
83
|
+
"-fsyntax-only",
|
|
84
|
+
"-x",
|
|
85
|
+
"objective-c",
|
|
86
|
+
"-isysroot",
|
|
87
|
+
SDK_PATH,
|
|
88
|
+
"-fmodules",
|
|
89
|
+
"-Xclang",
|
|
90
|
+
"-fparse-all-comments",
|
|
91
|
+
headerPath
|
|
92
|
+
],
|
|
93
|
+
{ stdout: "pipe", stderr: "ignore" }
|
|
94
|
+
);
|
|
95
|
+
const text = await new Response(proc.stdout).text();
|
|
96
|
+
await proc.exited;
|
|
97
|
+
return pruneAST(JSON.parse(text) as ClangASTNode);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Run clang on a header file WITHOUT -fmodules, using pre-includes instead.
|
|
102
|
+
* This is needed for some WebKit headers where -fmodules causes macro
|
|
103
|
+
* resolution issues (e.g., WK_EXTERN, API_AVAILABLE not expanding properly).
|
|
104
|
+
*/
|
|
105
|
+
export async function clangASTDumpWithPreIncludes(headerPath: string, preIncludes: string[]): Promise<ClangASTNode> {
|
|
106
|
+
const args = ["clang", "-Xclang", "-ast-dump=json", "-fsyntax-only", "-x", "objective-c", "-isysroot", SDK_PATH];
|
|
107
|
+
for (const inc of preIncludes) {
|
|
108
|
+
args.push("-include", inc);
|
|
109
|
+
}
|
|
110
|
+
args.push("-Xclang", "-fparse-all-comments");
|
|
111
|
+
args.push(headerPath);
|
|
112
|
+
|
|
113
|
+
const proc = Bun.spawn(args, { stdout: "pipe", stderr: "ignore" });
|
|
114
|
+
const text = await new Response(proc.stdout).text();
|
|
115
|
+
await proc.exited;
|
|
116
|
+
return pruneAST(JSON.parse(text) as ClangASTNode);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Run clang on multiple header files at once by creating a temporary .m file
|
|
121
|
+
* with #include directives for all headers. This avoids spawning a separate
|
|
122
|
+
* clang process per header, dramatically reducing total parse time.
|
|
123
|
+
*
|
|
124
|
+
* IMPORTANT: This runs WITHOUT -fmodules because modules deduplicate content
|
|
125
|
+
* and produce incomplete ASTs when batching. Instead, pre-includes are used
|
|
126
|
+
* to ensure macros (API_AVAILABLE, NS_ENUM, etc.) are properly expanded.
|
|
127
|
+
*
|
|
128
|
+
* @param headerPaths - Array of absolute paths to .h header files to include
|
|
129
|
+
* @param preIncludes - Headers to include before the batch (e.g., Foundation/Foundation.h)
|
|
130
|
+
* @param extraArgs - Additional clang arguments (e.g., ["-I", "/path/to/includes"])
|
|
131
|
+
*/
|
|
132
|
+
export async function clangBatchASTDump(
|
|
133
|
+
headerPaths: string[],
|
|
134
|
+
preIncludes: string[],
|
|
135
|
+
extraArgs?: string[]
|
|
136
|
+
): Promise<ClangASTNode> {
|
|
137
|
+
// Create a temporary .m file that includes all headers
|
|
138
|
+
const includes = headerPaths.map((p) => `#include "${p}"`).join("\n");
|
|
139
|
+
const tmpPath = `${Bun.env.TMPDIR ?? "/tmp"}/objcjs-batch-${Date.now()}-${Math.random().toString(36).slice(2)}.m`;
|
|
140
|
+
await Bun.write(tmpPath, includes + "\n");
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
const args = ["clang", "-Xclang", "-ast-dump=json", "-fsyntax-only", "-x", "objective-c", "-isysroot", SDK_PATH];
|
|
144
|
+
for (const inc of preIncludes) {
|
|
145
|
+
args.push("-include", inc);
|
|
146
|
+
}
|
|
147
|
+
if (extraArgs) {
|
|
148
|
+
args.push(...extraArgs);
|
|
149
|
+
}
|
|
150
|
+
args.push("-Xclang", "-fparse-all-comments");
|
|
151
|
+
args.push(tmpPath);
|
|
152
|
+
|
|
153
|
+
const proc = Bun.spawn(args, { stdout: "pipe", stderr: "ignore" });
|
|
154
|
+
const text = await new Response(proc.stdout).text();
|
|
155
|
+
await proc.exited;
|
|
156
|
+
return pruneAST(JSON.parse(text) as ClangASTNode);
|
|
157
|
+
} finally {
|
|
158
|
+
// Clean up temp file
|
|
159
|
+
try {
|
|
160
|
+
await Bun.write(tmpPath, "");
|
|
161
|
+
} catch {}
|
|
162
|
+
try {
|
|
163
|
+
const { unlink } = await import("fs/promises");
|
|
164
|
+
await unlink(tmpPath);
|
|
165
|
+
} catch {}
|
|
166
|
+
}
|
|
167
|
+
}
|