Gomuks SDK Rewrite #2
6 changed files with 78 additions and 101 deletions
working build scripts
commit
058f68cffb
|
|
@ -1,8 +1,11 @@
|
|||
import "dart:io";
|
||||
import "package:hooks/hooks.dart";
|
||||
import "package:code_assets/code_assets.dart";
|
||||
import "package:path/path.dart";
|
||||
|
||||
Future<void> main(List<String> args) => build(args, (input, output) async {
|
||||
final buildDir = input.packageRoot.resolve("build/");
|
||||
if (await File(buildDir.resolve("lock").toFilePath()).exists()) return;
|
||||
|
||||
final targetOS = input.config.code.targetOS;
|
||||
String libFileName;
|
||||
switch (targetOS) {
|
||||
|
|
@ -19,16 +22,29 @@ Future<void> main(List<String> args) => build(args, (input, output) async {
|
|||
throw UnsupportedError("Unsupported OS: $targetOS");
|
||||
}
|
||||
|
||||
final generatedFile = join("src", "third_party", "gomuks.g.dart");
|
||||
final gomuksBuildDir = buildDir.resolve("gomuks/");
|
||||
final libFile = gomuksBuildDir.resolve(libFileName);
|
||||
|
||||
print("Building Gomuks shared library $libFileName...");
|
||||
final result = await Process.run("go", [
|
||||
"build",
|
||||
"-o",
|
||||
libFile.path,
|
||||
"-buildmode=c-shared",
|
||||
], workingDirectory: gomuksBuildDir.resolve("source/pkg/ffi/").toFilePath());
|
||||
|
||||
if (result.exitCode != 0) {
|
||||
throw Exception("Failed to build Gomuks shared library\n${result.stderr}");
|
||||
}
|
||||
|
||||
final generatedFile = "src/third_party/gomuks.g.dart";
|
||||
output.assets.code.add(
|
||||
CodeAsset(
|
||||
package: "nexus",
|
||||
name: generatedFile,
|
||||
linkMode: DynamicLoadingBundled(),
|
||||
file: input.packageRoot.resolve(join("build", "gomuks", libFileName)),
|
||||
file: libFile,
|
||||
),
|
||||
);
|
||||
output.dependencies.add(
|
||||
input.packageRoot.resolve(join("lib", generatedFile)),
|
||||
);
|
||||
output.dependencies.add(input.packageRoot.resolve("lib/$generatedFile"));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -46,23 +46,14 @@ class ClientController extends Notifier<int> {
|
|||
return handle;
|
||||
}
|
||||
|
||||
(int requestId, Map<String, dynamic> response) sendCommand(
|
||||
String command,
|
||||
Map<String, dynamic> data,
|
||||
) {
|
||||
final responsePtr = calloc<GomuksBuffer>();
|
||||
try {
|
||||
final requestId = GomuksSubmitCommand(
|
||||
state,
|
||||
command.toNativeUtf8().cast<Char>(),
|
||||
data.toGomuksBuffer(),
|
||||
responsePtr,
|
||||
);
|
||||
void sendCommand(String command, Map<String, dynamic> data) {
|
||||
// final response = GomuksSubmitCommand(
|
||||
// state,
|
||||
// command.toNativeUtf8().cast<Char>(),
|
||||
// data.toGomuksBuffer(),
|
||||
// );
|
||||
|
||||
return (requestId, responsePtr.ref.toJson());
|
||||
} finally {
|
||||
calloc.free(responsePtr);
|
||||
}
|
||||
// return response.buf; TODO
|
||||
}
|
||||
|
||||
static final provider = NotifierProvider<ClientController, int>(
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@ import "package:ffi/ffi.dart";
|
|||
import "package:nexus/src/third_party/gomuks.g.dart";
|
||||
|
||||
extension GomuksBufferToJson on GomuksBorrowedBuffer {
|
||||
Uint8List toBytes() {
|
||||
if (base == nullptr || length <= 0) return Uint8List(0);
|
||||
return base.asTypedList(length);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final bytes = toBytes();
|
||||
if (bytes.isEmpty) return {};
|
||||
|
|
@ -14,21 +19,21 @@ extension GomuksBufferToJson on GomuksBorrowedBuffer {
|
|||
}
|
||||
|
||||
extension JsonToGomuksBuffer on Map<String, dynamic> {
|
||||
GomuksBuffer toGomuksBuffer() {
|
||||
final jsonString = json.encode(this);
|
||||
final bytes = utf8.encode(jsonString);
|
||||
// GomuksBorrowedBuffer toGomuksBuffer() {
|
||||
// final jsonString = json.encode(this);
|
||||
// final bytes = utf8.encode(jsonString);
|
||||
|
||||
final dataPtr = calloc<Uint8>(bytes.length);
|
||||
dataPtr.asTypedList(bytes.length).setAll(0, bytes);
|
||||
// final dataPtr = calloc<Uint8>(bytes.length);
|
||||
// dataPtr.asTypedList(bytes.length).setAll(0, bytes);
|
||||
|
||||
final bufPtr = calloc<GomuksBuffer>();
|
||||
bufPtr.ref.base = dataPtr;
|
||||
bufPtr.ref.length = bytes.length;
|
||||
// final bufPtr = calloc<GomuksBuffer>();
|
||||
// bufPtr.ref.base = dataPtr;
|
||||
// bufPtr.ref.length = bytes.length;
|
||||
|
||||
final bufByValue = bufPtr.ref;
|
||||
// final bufByValue = bufPtr.ref;
|
||||
|
||||
calloc.free(bufPtr);
|
||||
// calloc.free(bufPtr);
|
||||
|
||||
return bufByValue;
|
||||
}
|
||||
// return bufByValue;
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,6 @@ class App extends ConsumerWidget {
|
|||
"username": "quadradical",
|
||||
"password": "Quadmarad1!",
|
||||
});
|
||||
debugPrint("$response");
|
||||
return Placeholder();
|
||||
},
|
||||
// .betterWhen(
|
||||
|
|
|
|||
|
|
@ -3,34 +3,11 @@ 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);
|
||||
|
||||
final repoDir = Directory(join(buildDir.path, "source"));
|
||||
|
||||
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);
|
||||
await repoDir.create(recursive: true);
|
||||
|
||||
print("Cloning Gomuks repository...");
|
||||
final cloneResult = await Process.run("git", [
|
||||
|
|
@ -49,33 +26,13 @@ void main(List<String> args) async {
|
|||
);
|
||||
}
|
||||
|
||||
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...");
|
||||
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,
|
||||
|
|
|
|||
9
scripts/generate.sh
Executable file
9
scripts/generate.sh
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
pushd "$(dirname "$(readlink -f "$0")")"/.. || exit
|
||||
|
||||
mkdir -p build
|
||||
touch build/lock
|
||||
dart scripts/generate.dart
|
||||
rm build/lock
|
||||
|
||||
popd || exit
|
||||
Loading…
Add table
Add a link
Reference in a new issue