-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts"; | ||
import { m } from "https://raw.githubusercontent.com/glebbash/multiline-str/master/src/multiline-str.ts"; | ||
|
||
import { generateBindings, getFunctionsFromSharedLib } from "./mod.ts"; | ||
|
||
const cmd = new Command() | ||
.name("ffigen") | ||
.description("FFI Bindings generator for Deno.") | ||
.version("v0.0.1beta") | ||
.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.", | ||
{ default: "<lib-name>" }, | ||
) | ||
.helpOption("--help") | ||
.example( | ||
"headers", | ||
m` | ||
Headers option is used to generate links in description of each function. | ||
Example: "https://github.com/llvm/llvm-project/blob/release/14.x/llvm/include/" | ||
`, | ||
) | ||
.arguments("[outputFolder]"); | ||
|
||
const { args, options } = await cmd.parse(); | ||
|
||
const exposedFunctions = await getFunctionsFromSharedLib( | ||
options.symbols, | ||
); | ||
|
||
await generateBindings( | ||
options.definitions, | ||
exposedFunctions, | ||
args[0] ?? options.libName, | ||
options.libName, | ||
options.headers, | ||
options.libPrefix ?? options.libName, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,5 @@ | ||
import { generateBindings } from "./generate-bindings.ts"; | ||
import { getFunctionsFromSharedLib } from "./get-functions-from-shared-lib.ts"; | ||
|
||
// TODO: improve cli | ||
// TODO: clean up | ||
// TODO: check what can be done on struct support | ||
|
||
if (import.meta.main) { | ||
const [ | ||
allSymbolsFile, | ||
exposedSymbolsFile, | ||
outputFolder, | ||
libName, | ||
baseSourcePath, | ||
] = Deno.args; | ||
|
||
const exposedFunctions = await getFunctionsFromSharedLib( | ||
exposedSymbolsFile, | ||
); | ||
|
||
await generateBindings( | ||
allSymbolsFile, | ||
exposedFunctions, | ||
outputFolder, | ||
libName, | ||
baseSourcePath, | ||
); | ||
} | ||
export { generateBindings } from "./generate-bindings.ts"; | ||
export { getFunctionsFromSharedLib } from "./get-functions-from-shared-lib.ts"; |