Fork of daniellemaywood.uk/gleam — Wasm codegen work
1{
2 description = "Gleam compiler (wasm / Zed extension support fork)";
3
4 inputs = {
5 nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6 systems.url = "github:nix-systems/default";
7 fenix.url = "github:nix-community/fenix";
8 fenix.inputs.nixpkgs.follows = "nixpkgs";
9 };
10
11 outputs =
12 {
13 self,
14 nixpkgs,
15 systems,
16 fenix,
17 ...
18 }:
19 let
20 forEachSystem = nixpkgs.lib.genAttrs (import systems);
21 in
22 {
23 packages = forEachSystem (
24 system:
25 let
26 pkgs = nixpkgs.legacyPackages.${system};
27 inherit (pkgs) lib;
28
29 # Recent stable for edition 2024 workspace.
30 rustToolchain =
31 fenix.packages.${system}.stable.toolchain
32 or fenix.packages.${system}.complete.toolchain;
33
34 rustPlatform = pkgs.makeRustPlatform {
35 cargo = rustToolchain;
36 rustc = rustToolchain;
37 };
38
39 gleam = rustPlatform.buildRustPackage {
40 pname = "gleam";
41 version = "1.18.0-rc2";
42 src = lib.cleanSourceWith {
43 src = ./.;
44 filter =
45 path: type:
46 let
47 base = baseNameOf path;
48 in
49 lib.cleanSourceFilter path type
50 && base != "target"
51 && base != "result"
52 && !(lib.hasSuffix ".wasm" base)
53 && !(lib.hasSuffix ".cwasm" base);
54 };
55
56 cargoLock = {
57 lockFile = ./Cargo.lock;
58 };
59
60 nativeBuildInputs = [
61 pkgs.capnproto
62 pkgs.pkg-config
63 ];
64
65 # Workspace: only build/install the CLI crate.
66 buildAndTestSubdir = "gleam-bin";
67
68 # Full test suite is heavy and needs network / many backends.
69 doCheck = false;
70
71 meta = {
72 description = "Gleam compiler with Wasm / Zed extension export";
73 mainProgram = "gleam";
74 homepage = "https://tangled.org/nandi.uk/gleam";
75 license = lib.licenses.asl20;
76 };
77 };
78 in
79 {
80 default = gleam;
81 inherit gleam;
82 }
83 );
84
85 apps = forEachSystem (system: {
86 default = {
87 type = "app";
88 program = "${self.packages.${system}.gleam}/bin/gleam";
89 };
90 });
91
92 devShells = forEachSystem (
93 system:
94 let
95 pkgs = nixpkgs.legacyPackages.${system};
96 rustToolchain =
97 fenix.packages.${system}.stable.toolchain
98 or fenix.packages.${system}.complete.toolchain;
99 in
100 {
101 default = pkgs.mkShell {
102 packages = [
103 rustToolchain
104 pkgs.capnproto
105 pkgs.pkg-config
106 self.packages.${system}.gleam
107 ];
108 shellHook = ''
109 echo "gleam wasm fork dev shell"
110 echo " gleam --version # store build when packages.gleam is built"
111 echo " cargo build -p gleam"
112 '';
113 };
114 }
115 );
116
117 checks = forEachSystem (system: {
118 package = self.packages.${system}.gleam;
119 });
120
121 formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
122 };
123}