diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ad8184a..534a2d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,30 +29,24 @@ jobs: run: | curl -sfL https://direnv.net/install.sh | bash echo "$HOME/.local/bin" >> $GITHUB_PATH - # - name: Load environment variables - # run: | - # direnv allow . - # direnv export gha > "$GITHUB_ENV" - - # # Codegen - # - name: Run codegen - # run: melos run codegen - # - name: Ensure there are no diffs from codegen - # run: git diff --exit-code + - name: Load environment variables + run: | + direnv allow . + direnv export gha > "$GITHUB_ENV" # # Rust - # - name: Rust format - # run: cargo fmt --all --check # - name: Rust lint # run: cargo clippy -- -D warnings + # - name: Rust format + # run: cargo fmt --all --check # - name: Rust tests # run: cargo test - # # Dart/Flutter - # - name: Dart format - # run: dart format --set-exit-if-changed . - # - name: Dart lint - # run: flutter analyze --fatal-infos --fatal-warnings + # Dart/Flutter + - name: Dart lint + run: flutter analyze --fatal-infos --fatal-warnings + - name: Dart format + run: dart format --set-exit-if-changed . # - name: Dart tests # run: melos run test diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..04175fc --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1758690382, + "narHash": "sha256-NY3kSorgqE5LMm1LqNwGne3ZLMF2/ILgLpFr1fS4X3o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e643668fd71b949c53f8626614b21ff71a07379d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..74bce2b --- /dev/null +++ b/flake.nix @@ -0,0 +1,85 @@ +{ + description = "native_toolchain_rs"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + utils, + }: + utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + }; + in + { + formatter = pkgs.nixfmt-tree; + + devShells = { + default = pkgs.mkShell { + packages = with pkgs; [ + # TODO flutter335 but at version where native assets works + rustup + llvmPackages_20.clangUseLLVM + ]; + + env = { + RUST_BACKTRACE = "1"; + }; + + shellHook = '' + export PATH=$HOME/.pub-cache/bin:$PATH + dart pub global activate melos + ''; + }; + + android = + let + arch = builtins.head (builtins.split "-" system); + androidEnv = pkgs.androidenv.override { licenseAccepted = true; }; + androidComposition = androidEnv.composeAndroidPackages { + platformVersions = [ + "35" + "36" + ]; + buildToolsVersions = [ "35.0.0" ]; + cmakeVersions = [ "3.22.1" ]; + includeNDK = true; + ndkVersions = [ "27.0.12077973" ]; + + # For the emulator: + includeEmulator = true; + includeSystemImages = true; + systemImageTypes = [ "default" ]; + abiVersions = [ + { + "x86_64" = "x86_64"; + "aarch64" = "arm64-v8a"; + } + .${arch} or (throw "Unsupported architecture: ${arch}") + ]; + }; + in + pkgs.mkShell { + packages = with pkgs; [ + androidComposition.androidsdk + jdk17 + ]; + + env = rec { + ANDROID_HOME = "${androidComposition.androidsdk}/libexec/android-sdk"; + ANDROID_NDK_ROOT = "${ANDROID_HOME}/ndk-bundle"; + }; + }; + }; + } + ); +} diff --git a/lib/native_toolchain_rs.dart b/lib/native_toolchain_rs.dart index 3d1150b..f7845da 100644 --- a/lib/native_toolchain_rs.dart +++ b/lib/native_toolchain_rs.dart @@ -106,10 +106,6 @@ final class RustBuilder { tomlDocumentWrapperFactory: tomlDocumentWrapperFactory, cargoManifestParser: cargoManifestParser, toolchainTomlParser: toolchainTomlParser, - ).run( - input: input, - output: output, - assetRouting: assetRouting, - ); + ).run(input: input, output: output, assetRouting: assetRouting); } } diff --git a/lib/src/build_runner.dart b/lib/src/build_runner.dart index d4a513c..2fc78b7 100644 --- a/lib/src/build_runner.dart +++ b/lib/src/build_runner.dart @@ -94,10 +94,7 @@ final class RustBuildRunner { '--target-dir', outputDir, if (!enableDefaultFeatures) '--no-default-features', - if (features.isNotEmpty) ...[ - '--features', - features.join(','), - ], + if (features.isNotEmpty) ...['--features', features.join(',')], ...extraCargoBuildArgs, ], environment: { diff --git a/lib/src/toml_parsing.dart b/lib/src/toml_parsing.dart index 5975100..01690d4 100644 --- a/lib/src/toml_parsing.dart +++ b/lib/src/toml_parsing.dart @@ -72,10 +72,7 @@ final class CargoManifestParser { () => manifest.walk>('lib.crate-type').cast(), ]); - return ( - crateName: crateName, - libCrateTypes: libCrateTypes, - ); + return (crateName: crateName, libCrateTypes: libCrateTypes); } } @@ -114,9 +111,6 @@ final class ToolchainTomlParser { .toSet(), ]); - return ( - channel: channel, - targets: targets, - ); + return (channel: channel, targets: targets); } }