Skip to content

Commit b75071d

Browse files
chore(nix): setup nix flake (#9)
Fixes #4
1 parent fb523c5 commit b75071d

7 files changed

Lines changed: 162 additions & 34 deletions

File tree

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/build.yml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,24 @@ jobs:
2929
run: |
3030
curl -sfL https://direnv.net/install.sh | bash
3131
echo "$HOME/.local/bin" >> $GITHUB_PATH
32-
# - name: Load environment variables
33-
# run: |
34-
# direnv allow .
35-
# direnv export gha > "$GITHUB_ENV"
36-
37-
# # Codegen
38-
# - name: Run codegen
39-
# run: melos run codegen
40-
# - name: Ensure there are no diffs from codegen
41-
# run: git diff --exit-code
32+
- name: Load environment variables
33+
run: |
34+
direnv allow .
35+
direnv export gha > "$GITHUB_ENV"
4236
4337
# # Rust
44-
# - name: Rust format
45-
# run: cargo fmt --all --check
4638
# - name: Rust lint
4739
# run: cargo clippy -- -D warnings
40+
# - name: Rust format
41+
# run: cargo fmt --all --check
4842
# - name: Rust tests
4943
# run: cargo test
5044

51-
# # Dart/Flutter
52-
# - name: Dart format
53-
# run: dart format --set-exit-if-changed .
54-
# - name: Dart lint
55-
# run: flutter analyze --fatal-infos --fatal-warnings
45+
# Dart/Flutter
46+
- name: Dart lint
47+
run: flutter analyze --fatal-infos --fatal-warnings
48+
- name: Dart format
49+
run: dart format --set-exit-if-changed .
5650
# - name: Dart tests
5751
# run: melos run test
5852

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
description = "native_toolchain_rs";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs =
10+
{
11+
self,
12+
nixpkgs,
13+
utils,
14+
}:
15+
utils.lib.eachDefaultSystem (
16+
system:
17+
let
18+
pkgs = import nixpkgs {
19+
inherit system;
20+
config.allowUnfree = true;
21+
};
22+
in
23+
{
24+
formatter = pkgs.nixfmt-tree;
25+
26+
devShells = {
27+
default = pkgs.mkShell {
28+
packages = with pkgs; [
29+
# TODO flutter335 but at version where native assets works
30+
rustup
31+
llvmPackages_20.clangUseLLVM
32+
];
33+
34+
env = {
35+
RUST_BACKTRACE = "1";
36+
};
37+
38+
shellHook = ''
39+
export PATH=$HOME/.pub-cache/bin:$PATH
40+
dart pub global activate melos
41+
'';
42+
};
43+
44+
android =
45+
let
46+
arch = builtins.head (builtins.split "-" system);
47+
androidEnv = pkgs.androidenv.override { licenseAccepted = true; };
48+
androidComposition = androidEnv.composeAndroidPackages {
49+
platformVersions = [
50+
"35"
51+
"36"
52+
];
53+
buildToolsVersions = [ "35.0.0" ];
54+
cmakeVersions = [ "3.22.1" ];
55+
includeNDK = true;
56+
ndkVersions = [ "27.0.12077973" ];
57+
58+
# For the emulator:
59+
includeEmulator = true;
60+
includeSystemImages = true;
61+
systemImageTypes = [ "default" ];
62+
abiVersions = [
63+
{
64+
"x86_64" = "x86_64";
65+
"aarch64" = "arm64-v8a";
66+
}
67+
.${arch} or (throw "Unsupported architecture: ${arch}")
68+
];
69+
};
70+
in
71+
pkgs.mkShell {
72+
packages = with pkgs; [
73+
androidComposition.androidsdk
74+
jdk17
75+
];
76+
77+
env = rec {
78+
ANDROID_HOME = "${androidComposition.androidsdk}/libexec/android-sdk";
79+
ANDROID_NDK_ROOT = "${ANDROID_HOME}/ndk-bundle";
80+
};
81+
};
82+
};
83+
}
84+
);
85+
}

lib/native_toolchain_rs.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ final class RustBuilder {
106106
tomlDocumentWrapperFactory: tomlDocumentWrapperFactory,
107107
cargoManifestParser: cargoManifestParser,
108108
toolchainTomlParser: toolchainTomlParser,
109-
).run(
110-
input: input,
111-
output: output,
112-
assetRouting: assetRouting,
113-
);
109+
).run(input: input, output: output, assetRouting: assetRouting);
114110
}
115111
}

lib/src/build_runner.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ final class RustBuildRunner {
9494
'--target-dir',
9595
outputDir,
9696
if (!enableDefaultFeatures) '--no-default-features',
97-
if (features.isNotEmpty) ...[
98-
'--features',
99-
features.join(','),
100-
],
97+
if (features.isNotEmpty) ...['--features', features.join(',')],
10198
...extraCargoBuildArgs,
10299
],
103100
environment: {

lib/src/toml_parsing.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ final class CargoManifestParser {
7272
() => manifest.walk<List<dynamic>>('lib.crate-type').cast<String>(),
7373
]);
7474

75-
return (
76-
crateName: crateName,
77-
libCrateTypes: libCrateTypes,
78-
);
75+
return (crateName: crateName, libCrateTypes: libCrateTypes);
7976
}
8077
}
8178

@@ -114,9 +111,6 @@ final class ToolchainTomlParser {
114111
.toSet(),
115112
]);
116113

117-
return (
118-
channel: channel,
119-
targets: targets,
120-
);
114+
return (channel: channel, targets: targets);
121115
}
122116
}

0 commit comments

Comments
 (0)