Skip to content

Commit 07cc020

Browse files
committed
add flake which builds lute
0 parents  commit 07cc020

File tree

4 files changed

+279
-0
lines changed

4 files changed

+279
-0
lines changed

deps.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[
2+
{
3+
"name": "boringssl",
4+
"url": "https://github.com/google/boringssl.git",
5+
"revision": "2b44a3701a4788e1ef866ddc7f143060a3d196c9",
6+
"sha256": "1bagg4mx7i1fi1qq38za6rginva7xs48bm0dq7h5vs5wmnv6wrpw"
7+
},
8+
{
9+
"name": "curl",
10+
"url": "https://github.com/curl/curl.git",
11+
"revision": "1c3149881769e7bd79b072e48374e4c2b3678b2f",
12+
"sha256": "1hfxb0931ks52ajjf44h9jr7d2i1nl6n2bimhdk81bdnv5c0dq46"
13+
},
14+
{
15+
"name": "libsodium",
16+
"url": "https://github.com/jedisct1/libsodium.git",
17+
"revision": "9511c982fb1d046470a8b42aa36556cdb7da15de",
18+
"sha256": "0q5502p4fm099aiwprn5396ki0ppdv8ajjj2v19md0jijql77xb4"
19+
},
20+
{
21+
"name": "libuv",
22+
"url": "https://github.com/libuv/libuv.git",
23+
"revision": "8fb9cb919489a48880680a56efecff6a7dfb4504",
24+
"sha256": "15g6ad56gjdcxmw6s7nicil4fshw6pbldpcip8wk6q4ri9zz77ym"
25+
},
26+
{
27+
"name": "luau",
28+
"url": "https://github.com/luau-lang/luau.git",
29+
"revision": "54a2ea00831df4c791e6cfc896a98da75d1ae126",
30+
"sha256": "0y1w7wzi6j0xsy7ixc18n32qf9n5z7dzhcdvk0q2f66axsk70q4q"
31+
},
32+
{
33+
"name": "uSockets",
34+
"url": "https://github.com/uNetworking/uSockets.git",
35+
"revision": "833497e8e0988f7fd8d33cd4f6f36056c68d225d",
36+
"sha256": "02f8qd4nv0d1qydkib2wkp137aid1vkp3qscazgxh38sgpcrhp36"
37+
},
38+
{
39+
"name": "uWebSockets",
40+
"url": "https://github.com/uNetworking/uWebSockets.git",
41+
"revision": "c445faa38125bf782eed3fec97f83b4733c7fb91",
42+
"sha256": "1gyxnljaghd97c9h5hnawxszfg1xnl3r5qysvxcksby8lidjnh04"
43+
},
44+
{
45+
"name": "zlib",
46+
"url": "https://github.com/madler/zlib.git",
47+
"revision": "51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf",
48+
"sha256": "12r98gay98w6vd1m6v1xw6k3yzc4yb7r3x6h5zjw6hbr4dcwnhsf"
49+
}
50+
]

flake.lock

Lines changed: 43 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: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "nixpkgs/nixos-unstable";
4+
5+
lute-src = {
6+
url = "github:luau-lang/lute";
7+
flake = false;
8+
};
9+
};
10+
11+
outputs = {
12+
self,
13+
nixpkgs,
14+
lute-src,
15+
...
16+
}: let
17+
inherit (nixpkgs) lib;
18+
19+
forAllSystems = f:
20+
lib.genAttrs lib.systems.flakeExposed (system: f nixpkgs.legacyPackages.${system});
21+
in {
22+
packages = forAllSystems (pkgs: let
23+
deps = builtins.fromJSON (builtins.readFile ./deps.json);
24+
extern = lib.listToAttrs (map (dep: {
25+
name = dep.name;
26+
value = pkgs.fetchgit {
27+
url = dep.url;
28+
rev = dep.revision;
29+
sha256 = dep.sha256;
30+
fetchSubmodules = false;
31+
};
32+
}) deps);
33+
34+
copyExterns = lib.concatStringsSep "\n" (lib.mapAttrsToList (name: path: ''
35+
cp -R --no-preserve=mode ${path} extern/${name}
36+
'') extern);
37+
in {
38+
default = pkgs.llvmPackages_18.libcxxStdenv.mkDerivation {
39+
pname = "lute";
40+
version = "0.1.0";
41+
42+
src = lute-src;
43+
44+
nativeBuildInputs = with pkgs; [
45+
cmake
46+
ninja
47+
git
48+
];
49+
50+
dontConfigure = true;
51+
52+
buildPhase = ''
53+
runHook preBuild
54+
55+
${copyExterns}
56+
57+
mkdir -p lute/std/src/generated
58+
cp tools/templates/std_impl.cpp lute/std/src/generated/modules.cpp
59+
cp tools/templates/std_header.h lute/std/src/generated/modules.h
60+
61+
mkdir -p lute/cli/generated
62+
cp tools/templates/cli_impl.cpp lute/cli/generated/commands.cpp
63+
cp tools/templates/cli_header.h lute/cli/generated/commands.h
64+
65+
cmake -G Ninja -B build/debug -DCMAKE_BUILD_TYPE=Debug
66+
ninja -C build/debug lute/cli/lute
67+
68+
mv build/debug/lute/cli/lute build/lute0
69+
70+
# Precompute the tune hash so luthier won't fetch deps.
71+
mkdir -p extern/generated
72+
tmp_hash_input="$(mktemp)"
73+
LC_ALL=C find extern -maxdepth 1 -type f -name '*.tune' -printf '%f\n' | sort | while read -r name; do
74+
printf "%s" "$name" >> "$tmp_hash_input"
75+
cat "extern/$name" >> "$tmp_hash_input"
76+
done
77+
tune_hash="$(b2sum --length=256 "$tmp_hash_input" | cut -d' ' -f1)"
78+
printf "%s" "$tune_hash" > extern/generated/hash.txt
79+
rm -f "$tmp_hash_input"
80+
81+
build/lute0 tools/luthier.luau configure --config release --clean lute
82+
build/lute0 tools/luthier.luau build --config release --clean lute
83+
84+
runHook postBuild
85+
'';
86+
87+
installPhase = ''
88+
runHook preInstall
89+
90+
mkdir -p $out/bin
91+
cp build/release/lute/cli/lute $out/bin/lute
92+
93+
runHook postInstall
94+
'';
95+
96+
checkPhase = ''
97+
runHook preCheck
98+
99+
export HOME="$TMPDIR"
100+
ninja -C build/release tests/lute-tests
101+
./build/release/tests/lute-tests
102+
103+
runHook postCheck
104+
'';
105+
106+
doCheck = false;
107+
};
108+
});
109+
110+
checks = lib.genAttrs lib.systems.flakeExposed (system: {
111+
lute-tests = self.packages.${system}.default.overrideAttrs (old: {
112+
doCheck = true;
113+
});
114+
});
115+
116+
apps = forAllSystems (pkgs: {
117+
update-deps = {
118+
type = "app";
119+
meta = {
120+
description = "A script which fetches lute dep hashes";
121+
};
122+
program = toString (pkgs.writeShellScript "update-deps" ''
123+
export PATH="${lib.makeBinPath [ pkgs.nushell pkgs.nix-prefetch-git ]}:$PATH"
124+
exec nu ${./update-deps.nu} --lute-path ${lute-src} --out deps.json
125+
'');
126+
};
127+
});
128+
};
129+
}

update-deps.nu

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env nu
2+
3+
def fail [msg: string] {
4+
error make { msg: $msg }
5+
}
6+
7+
def prefetch_hash [remote: string, revision: string] {
8+
let args = ["--url", $remote, "--rev", $revision]
9+
let result = (^nix-prefetch-git ...$args | from json)
10+
$result.sha256
11+
}
12+
13+
def main [
14+
--lute-path: string = ""
15+
--out: string = "deps.json"
16+
] {
17+
let repo_root = ($env.PWD | path expand)
18+
let lute_path = if $lute_path != "" {
19+
($lute_path | path expand)
20+
} else {
21+
fail "no Lute path provided and ./lute not found"
22+
}
23+
24+
let extern_dir = ($lute_path | path join "extern")
25+
if not ($extern_dir | path exists) {
26+
fail $"extern/ not found at: ($extern_dir)"
27+
}
28+
29+
let tunes = (ls $extern_dir | where name ends-with ".tune" | sort-by name)
30+
if ($tunes | is-empty) {
31+
fail $"no .tune files found in: ($extern_dir)"
32+
}
33+
34+
let deps = ($tunes | each { |t|
35+
let doc = (open --raw $t.name | from toml)
36+
let depinfo = $doc.dependency
37+
38+
let name = $depinfo.name
39+
let remote = $depinfo.remote
40+
let revision = $depinfo.revision
41+
if ($name | is-empty) or ($remote | is-empty) or ($revision | is-empty) {
42+
fail $"missing fields in: ($t.name)"
43+
}
44+
45+
let sha256 = (prefetch_hash $remote $revision)
46+
47+
{
48+
name: $name,
49+
url: $remote,
50+
revision: $revision,
51+
sha256: $sha256,
52+
}
53+
})
54+
55+
let out_path = ($repo_root | path join $out)
56+
$deps | sort-by name | to json | save -f $out_path
57+
}

0 commit comments

Comments
 (0)