-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.ts
74 lines (69 loc) · 1.99 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Command } from "https://deno.land/x/cliffy@v0.24.3/command/mod.ts";
import { m } from "https://raw.githubusercontent.com/glebbash/multiline-str/master/src/multiline-str.ts";
import { generateBindings } from "./mod.ts";
const LIB_VERSION = "v0.2.1";
const cmd = new Command()
.name("ffigen")
.description("FFI Bindings generator for Deno.")
.version(LIB_VERSION)
.option(
"-s, --symbols <symbols-file>",
"Exposed symbols file (readelf output).",
{
required: true,
},
)
.option(
"-d, --definitions <definitions-file>",
"Definitions file. (c2ffi json output).",
{
required: true,
},
)
.option(
"-h, --headers <headers>",
"Base url for the headers of target library.",
{
required: true,
},
)
.option(
"-n, --lib-name <lib-name>",
"Name of the C library and generated namespace.",
{
required: true,
},
)
.option(
"-p, --lib-prefix [lib-prefix]",
"Library prefix to strip from all symbols.",
)
.option("--no-lib-prefix", "Disable prefix stripping.")
.helpOption("--help")
.example(
"headers",
m`
<headers> is used to generate links in description of each function.
Example: "https://github.com/llvm/llvm-project/blob/release/14.x/llvm/include/"
`,
)
.example(
"prefix",
m`
<lib-name> is used to strip prefix from all symbols.
For example if <lib-name> is LLVM and function name is LLVMContextCreate,
the generated function will be accessible as LLVM.ContextCreate.
You can set <lib-prefix> to set the specific prefix without
changing the namespace name.
`,
)
.arguments("[output-folder]");
const { args, options } = await cmd.parse();
await generateBindings({
symbolsFile: options.definitions,
exposedSymbolsFile: options.symbols,
outputFolder: args[0] ?? options.libName,
libName: options.libName,
headersBaseUrl: options.headers,
libPrefix: options.libPrefix === false ? "" : options.libPrefix as string,
});