diff --git a/.gitignore b/.gitignore index dfaf03d..d6616e1 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ key.properties # Generated Files *.g.dart *.freezed.dart +src/ # Devel Password password.txt \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 17d64ba..0000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "gomuks"] - path = gomuks - url = https://github.com/zachatrocity/gomuks - branch = init-root-dir diff --git a/README.md b/README.md index 7af23a0..cf652af 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ A simple and user-friendly Matrix client made with Flutter and a Gomuks backend. First, clone and open the repo: ```sh -git clone --recurse-submodules https://git.federated.nexus/Henry-Hiles/nexus +git clone https://git.federated.nexus/Henry-Hiles/nexus cd nexus ``` @@ -138,12 +138,12 @@ cd nexus #### Linux -- With Nix: Either use direnv and `direnv allow`, or `nix flake develop` +- With Nix: Either use direnv, or `nix flake develop` - Without Nix: Install Flutter, Go, Olm, Git, Clang, and GLibc. #### Windows / MacOS -I don't really know. You will need Flutter, Git, Go, and Visual Studio tools, and otherwise I guess just keep installing stuff until there aren't any errors. I will look into this sometimeTM. +I don't really know. You will need Flutter, Git, Olm, Go, and Visual Studio tools, and otherwise I guess just keep installing stuff until there aren't any errors. I will look into this sometimeTM. ### Set up Flutter @@ -153,7 +153,13 @@ Get dependencies: flutter pub get ``` -Generate Gomuks bindings: +Get dependencies: + +```sh +flutter pub get +``` + +Clone Gomuks and generate bindings: ```sh scripts/generate.sh diff --git a/gomuks b/gomuks deleted file mode 160000 index daa0ba0..0000000 --- a/gomuks +++ /dev/null @@ -1 +0,0 @@ -Subproject commit daa0ba028e7d89ba9fc7580fc8099348e6145cb3 diff --git a/hook/build.dart b/hook/build.dart index 52df9c4..fca2270 100644 --- a/hook/build.dart +++ b/hook/build.dart @@ -3,7 +3,7 @@ import "package:hooks/hooks.dart"; import "package:code_assets/code_assets.dart"; Future main(List args) => build(args, (input, output) async { - final buildDir = input.packageRoot.resolve("build/"); + final buildDir = input.packageRoot.resolve("src/"); if (await File(buildDir.resolve("lock").toFilePath()).exists()) return; final codeConfig = input.config.code; @@ -27,11 +27,10 @@ Future main(List args) => build(args, (input, output) async { final targetNdkApi = codeConfig.android.targetNdkApi; - final ndkHome = - Platform.environment["ANDROID_NDK_HOME"] ?? - Platform.environment["ANDROID_NDK_ROOT"] ?? - Platform.environment["NDK_HOME"] ?? - await _findNdkFromSdk(); + final ndkHome = Platform.environment["ANDROID_NDK_HOME"] + ?? Platform.environment["ANDROID_NDK_ROOT"] + ?? Platform.environment["NDK_HOME"] + ?? await _findNdkFromSdk(); if (ndkHome == null) { throw Exception( "Could not find Android NDK. Set ANDROID_NDK_HOME or install via sdkmanager.", @@ -40,30 +39,34 @@ Future main(List args) => build(args, (input, output) async { final hostTag = _ndkHostTag(); final (goArch, ccTriple) = _androidArch(targetArch); - final cc = - "$ndkHome/toolchains/llvm/prebuilt/$hostTag/bin/$ccTriple$targetNdkApi-clang"; + final cc = "$ndkHome/toolchains/llvm/prebuilt/$hostTag/bin/$ccTriple$targetNdkApi-clang"; - env = {"CGO_ENABLED": "1", "GOOS": "android", "GOARCH": goArch, "CC": cc}; + env = { + "CGO_ENABLED": "1", + "GOOS": "android", + "GOARCH": goArch, + "CC": cc, + }; break; default: throw UnsupportedError("Unsupported OS: $targetOS"); } - final gomuksBuildDir = input.packageRoot.resolve("gomuks/"); - final libFile = buildDir.resolve("${targetArch.name}/$libFileName"); + final gomuksBuildDir = buildDir.resolve("gomuks/"); + final libFile = gomuksBuildDir.resolve("${targetArch.name}/$libFileName"); // goheif/dav1d supported on Android would need to fix upstream final tags = targetOS == OS.android ? "goolm,noheic" : "goolm"; - print( - "Building Gomuks shared library $libFileName (${targetOS.name}/${targetArch.name}) from source...", - ); - final result = await Process.run( - "go", - ["build", "-tags", tags, "-o", libFile.path, "-buildmode=c-shared"], - workingDirectory: gomuksBuildDir.resolve("pkg/ffi/").toFilePath(), - environment: env.isNotEmpty ? env : null, - ); + print("Building Gomuks shared library $libFileName (${targetOS.name}/${targetArch.name}) from source..."); + final result = await Process.run("go", [ + "build", + "-tags", tags, + "-o", + libFile.path, + "-buildmode=c-shared", + ], workingDirectory: gomuksBuildDir.resolve("source/pkg/ffi/").toFilePath(), + environment: env.isNotEmpty ? env : null); if (result.exitCode != 0) { throw Exception("Failed to build Gomuks shared library\n${result.stderr}"); @@ -87,9 +90,8 @@ Future main(List args) => build(args, (input, output) async { Future _findNdkFromSdk() async { // pretty sure this wont be needed with nix, i'll get this removed - final androidHome = - Platform.environment["ANDROID_HOME"] ?? - Platform.environment["ANDROID_SDK_ROOT"]; + final androidHome = Platform.environment["ANDROID_HOME"] + ?? Platform.environment["ANDROID_SDK_ROOT"]; if (androidHome == null) return null; final ndkDir = Directory("$androidHome/ndk"); if (!await ndkDir.exists()) return null; diff --git a/scripts/generate.dart b/scripts/generate.dart index 446a469..b6b5453 100644 --- a/scripts/generate.dart +++ b/scripts/generate.dart @@ -3,7 +3,39 @@ import "package:ffigen/ffigen.dart"; import "package:path/path.dart"; void main(List args) async { - final repoDir = Directory.fromUri(Platform.script.resolve("../gomuks")); + final repoDir = Directory.fromUri( + Platform.script.resolve("../src/gomuks/source"), + ); + if (await repoDir.exists()) await repoDir.delete(recursive: true); + await repoDir.create(recursive: true); + + print("Cloning Gomuks repository..."); + final cloneResult = await Process.run("git", [ + "clone", + "https://github.com/zachatrocity/gomuks", + repoDir.path, + ]); + + if (cloneResult.exitCode != 0) { + throw Exception( + "Failed to clone Gomuks repository: \n${cloneResult.stderr}", + ); + } + + final commit = await File.fromUri( + Platform.script.resolve("../gomuks.lock"), + ).readAsString(); + + final checkoutResult = await Process.run("git", [ + "checkout", + commit, + ], workingDirectory: repoDir.path); + + if (checkoutResult.exitCode != 0) { + throw Exception( + "Failed to check out locked commit: \n${checkoutResult.stderr}", + ); + } print("Generating FFI Bindings...");