Gomuks SDK Rewrite #2

Closed
Henry-Hiles wants to merge 34 commits from go into main
Showing only changes of commit c332d7361c - Show all commits

add skip param

Henry Hiles 2026-01-24 11:56:03 +00:00
No known key found for this signature in database

View file

@ -3,7 +3,6 @@ import "package:ffigen/ffigen.dart";
import "package:path/path.dart"; import "package:path/path.dart";
void main(List<String> args) async { void main(List<String> args) async {
// Where we put the Gomuks repo and compiled library
final buildDir = Directory.fromUri( final buildDir = Directory.fromUri(
Platform.script.resolve(join("..", "build", "gomuks")), Platform.script.resolve(join("..", "build", "gomuks")),
); );
@ -11,7 +10,7 @@ void main(List<String> args) async {
final repoDir = Directory(join(buildDir.path, "source")); final repoDir = Directory(join(buildDir.path, "source"));
bool skipBuild = false; var skipBuild = args.contains("--skip");
final generatedSourcePath = join("src", "third_party", "gomuks.g.dart"); final generatedSourcePath = join("src", "third_party", "gomuks.g.dart");
final generatedLibPath = Platform.script.resolve( final generatedLibPath = Platform.script.resolve(
@ -19,9 +18,7 @@ void main(List<String> args) async {
); );
final bindingsFile = File(generatedLibPath.toFilePath()); final bindingsFile = File(generatedLibPath.toFilePath());
if (await bindingsFile.exists() && if (await bindingsFile.exists() && await repoDir.exists()) {
await repoDir.exists() &&
!args.contains("--rebuild")) {
final result = await Process.run("git", [ final result = await Process.run("git", [
"fetch", "fetch",
"--dry-run", "--dry-run",
@ -32,46 +29,43 @@ void main(List<String> args) async {
} }
} }
if (skipBuild) { if (!skipBuild) {
return print( if (await repoDir.exists()) await repoDir.delete(recursive: true);
"Gomuks build skipped: bindings and library exist and repo is up to date.",
);
}
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,
]);
print("Cloning Gomuks repository..."); if (cloneResult.exitCode != 0) {
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( throw Exception(
"Failed to build Gomuks shared library\n${result.stderr}", "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}",
);
}
}
} }
print("Generating FFI Bindings..."); print("Generating FFI Bindings...");
@ -82,7 +76,7 @@ void main(List<String> args) async {
), ),
headers: Headers( headers: Headers(
entryPoints: [File(join(buildDir.path, "libgomuks.h")).uri], entryPoints: [File(join(buildDir.path, "libgomuks.h")).uri],
compilerOptions: ["-I${String.fromEnvironment("CPATH")}"], // compilerOptions: ["-I${String.fromEnvironment("CPATH")}"],
), ),
functions: Functions.includeAll, functions: Functions.includeAll,
).generate(); ).generate();