working build scripts
This commit is contained in:
parent
8d43313512
commit
058f68cffb
6 changed files with 78 additions and 101 deletions
|
|
@ -3,79 +3,36 @@ import "package:ffigen/ffigen.dart";
|
|||
import "package:path/path.dart";
|
||||
|
||||
void main(List<String> args) async {
|
||||
final buildDir = Directory.fromUri(
|
||||
Platform.script.resolve(join("..", "build", "gomuks")),
|
||||
final repoDir = Directory.fromUri(
|
||||
Platform.script.resolve("../build/gomuks/source"),
|
||||
);
|
||||
if (!await buildDir.exists()) await buildDir.create(recursive: true);
|
||||
if (await repoDir.exists()) await repoDir.delete(recursive: true);
|
||||
await repoDir.create(recursive: true);
|
||||
|
||||
final repoDir = Directory(join(buildDir.path, "source"));
|
||||
print("Cloning Gomuks repository...");
|
||||
final cloneResult = await Process.run("git", [
|
||||
"clone",
|
||||
"--branch",
|
||||
"tulir/ffi",
|
||||
"--depth",
|
||||
"1",
|
||||
"https://mau.dev/gomuks/gomuks",
|
||||
repoDir.path,
|
||||
]);
|
||||
|
||||
var skipBuild = args.contains("--skip");
|
||||
|
||||
final generatedSourcePath = join("src", "third_party", "gomuks.g.dart");
|
||||
final generatedLibPath = Platform.script.resolve(
|
||||
join("..", "lib", generatedSourcePath),
|
||||
);
|
||||
final bindingsFile = File(generatedLibPath.toFilePath());
|
||||
|
||||
if (await bindingsFile.exists() && await repoDir.exists()) {
|
||||
final result = await Process.run("git", [
|
||||
"fetch",
|
||||
"--dry-run",
|
||||
], workingDirectory: repoDir.path);
|
||||
|
||||
if ((result.stdout as String).trim().isEmpty) {
|
||||
skipBuild = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skipBuild) {
|
||||
if (await repoDir.exists()) await repoDir.delete(recursive: true);
|
||||
|
||||
print("Cloning Gomuks repository...");
|
||||
final cloneResult = await Process.run("git", [
|
||||
"clone",
|
||||
"--branch",
|
||||
"tulir/ffi",
|
||||
"--depth",
|
||||
"1",
|
||||
"https://mau.dev/gomuks/gomuks",
|
||||
repoDir.path,
|
||||
]);
|
||||
|
||||
if (cloneResult.exitCode != 0) {
|
||||
throw Exception(
|
||||
"Failed to clone Gomuks repository: \n${cloneResult.stderr}",
|
||||
);
|
||||
}
|
||||
|
||||
for (final name in ["libgomuks.so", "libgomuks.dylib", "libgomuks.dll"]) {
|
||||
final libFile = File(join(buildDir.path, name));
|
||||
|
||||
print("Building Gomuks shared library $name...");
|
||||
final result = await Process.run("go", [
|
||||
"build",
|
||||
"-o",
|
||||
libFile.path,
|
||||
"-buildmode=c-shared",
|
||||
], workingDirectory: join(repoDir.path, "pkg/ffi"));
|
||||
|
||||
if (result.exitCode != 0) {
|
||||
throw Exception(
|
||||
"Failed to build Gomuks shared library\n${result.stderr}",
|
||||
);
|
||||
}
|
||||
}
|
||||
if (cloneResult.exitCode != 0) {
|
||||
throw Exception(
|
||||
"Failed to clone Gomuks repository: \n${cloneResult.stderr}",
|
||||
);
|
||||
}
|
||||
|
||||
print("Generating FFI Bindings...");
|
||||
final packageRoot = Platform.script.resolve("../");
|
||||
FfiGenerator(
|
||||
output: Output(
|
||||
dartFile: packageRoot.resolve("lib/src/third_party/gomuks.g.dart"),
|
||||
dartFile: Platform.script.resolve("../lib/src/third_party/gomuks.g.dart"),
|
||||
),
|
||||
headers: Headers(
|
||||
entryPoints: [File(join(buildDir.path, "libgomuks.h")).uri],
|
||||
entryPoints: [File(join(repoDir.path, "pkg", "ffi", "ffi.h")).uri],
|
||||
compilerOptions: ["--no-warnings"],
|
||||
),
|
||||
functions: Functions.includeAll,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue