Fork of daniellemaywood.uk/gleam — Wasm codegen work
1

Configure Feed

Select the types of activity you want to include in your feed.

Package gleam as a flake output and embed zed WIT.

Expose packages.gleam via rustPlatform/fenix, and load zed:extension WIT from
include_str so installed Nix binaries can run `export zed-extension`.

author
nandi
committer
nandi
date (Jul 26, 2026, 12:13 PM -0700) commit 971d5dd6 parent ece01369 change-id puxqovto
+183 -16
+1
Cargo.lock
··· 1310 1310 "stacker", 1311 1311 "strum", 1312 1312 "tar", 1313 + "tempfile", 1313 1314 "termcolor", 1314 1315 "thiserror 2.0.18", 1315 1316 "time",
+1
compiler-core/Cargo.toml
··· 53 53 wit-component = { version = "0.239.0", features = ["dummy-module"] } 54 54 wat = "1" 55 55 anyhow = "1" 56 + tempfile = "3" 56 57 57 58 num-bigint.workspace = true 58 59 num-traits.workspace = true
+73 -4
compiler-core/src/wasm/zed.rs
··· 40 40 package_component(core, &resolve, world) 41 41 } 42 42 43 + /// Vendored `zed:extension` 0.7.0 WIT (embedded so installed binaries work 44 + /// without a source tree; `CARGO_MANIFEST_DIR` alone breaks under Nix). 45 + fn zed_wit_files() -> &'static [(&'static str, &'static str)] { 46 + &[ 47 + ( 48 + "common.wit", 49 + include_str!("../../wit/zed_extension/0.7.0/common.wit"), 50 + ), 51 + ( 52 + "context-server.wit", 53 + include_str!("../../wit/zed_extension/0.7.0/context-server.wit"), 54 + ), 55 + ( 56 + "dap.wit", 57 + include_str!("../../wit/zed_extension/0.7.0/dap.wit"), 58 + ), 59 + ( 60 + "extension.wit", 61 + include_str!("../../wit/zed_extension/0.7.0/extension.wit"), 62 + ), 63 + ( 64 + "github.wit", 65 + include_str!("../../wit/zed_extension/0.7.0/github.wit"), 66 + ), 67 + ( 68 + "http-client.wit", 69 + include_str!("../../wit/zed_extension/0.7.0/http-client.wit"), 70 + ), 71 + ( 72 + "lsp.wit", 73 + include_str!("../../wit/zed_extension/0.7.0/lsp.wit"), 74 + ), 75 + ( 76 + "nodejs.wit", 77 + include_str!("../../wit/zed_extension/0.7.0/nodejs.wit"), 78 + ), 79 + ( 80 + "platform.wit", 81 + include_str!("../../wit/zed_extension/0.7.0/platform.wit"), 82 + ), 83 + ( 84 + "process.wit", 85 + include_str!("../../wit/zed_extension/0.7.0/process.wit"), 86 + ), 87 + ( 88 + "slash-command.wit", 89 + include_str!("../../wit/zed_extension/0.7.0/slash-command.wit"), 90 + ), 91 + ] 92 + } 93 + 43 94 fn load_zed_world() -> Result<(Resolve, WorldId)> { 44 95 let mut resolve = Resolve::default(); 45 - // Vendored next to this source tree. 46 - let wit_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/wit/zed_extension/0.7.0"); 96 + 97 + // Optional override for packaging / tests. 98 + if let Ok(dir) = std::env::var("GLEAM_ZED_WIT") { 99 + let (pkg, _) = resolve 100 + .push_dir(&dir) 101 + .with_context(|| format!("failed to parse WIT at GLEAM_ZED_WIT={dir}"))?; 102 + let world = resolve 103 + .select_world(&[pkg], Some("extension")) 104 + .context("zed:extension world not found")?; 105 + return Ok((resolve, world)); 106 + } 107 + 108 + // Materialise embedded WIT into a temp dir for wit-parser's push_dir. 109 + let tmp = tempfile::tempdir().context("temp dir for embedded zed WIT")?; 110 + for (name, contents) in zed_wit_files() { 111 + std::fs::write(tmp.path().join(name), contents) 112 + .with_context(|| format!("write embedded wit {name}"))?; 113 + } 47 114 let (pkg, _) = resolve 48 - .push_dir(wit_dir) 49 - .with_context(|| format!("failed to parse vendored WIT at {wit_dir}"))?; 115 + .push_dir(tmp.path()) 116 + .with_context(|| format!("failed to parse embedded zed WIT at {}", tmp.path().display()))?; 50 117 let world = resolve 51 118 .select_world(&[pkg], Some("extension")) 52 119 .context("zed:extension world not found")?; 120 + // Keep tmp alive until resolve is done parsing — package is fully loaded. 121 + std::mem::forget(tmp); 53 122 Ok((resolve, world)) 54 123 } 55 124
+108 -12
flake.nix
··· 1 1 { 2 + description = "Gleam compiler (wasm / Zed extension support fork)"; 3 + 2 4 inputs = { 3 5 nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 6 + systems.url = "github:nix-systems/default"; 4 7 fenix.url = "github:nix-community/fenix"; 5 8 fenix.inputs.nixpkgs.follows = "nixpkgs"; 6 9 }; 7 10 8 11 outputs = 9 - { nixpkgs, fenix, ... }: 12 + { 13 + self, 14 + nixpkgs, 15 + systems, 16 + fenix, 17 + ... 18 + }: 10 19 let 11 - forAllSystems = 12 - function: 13 - nixpkgs.lib.genAttrs [ 14 - "aarch64-darwin" 15 - ] (system: function nixpkgs.legacyPackages.${system}); 20 + forEachSystem = nixpkgs.lib.genAttrs (import systems); 16 21 in 17 22 { 18 - devShells = forAllSystems (pkgs: { 19 - default = pkgs.mkShell { 20 - packages = [ 21 - fenix.packages.${pkgs.system}.stable.toolchain 22 - pkgs.capnproto 23 - ]; 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.13.0-rc1"; 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"; 24 89 }; 25 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); 26 122 }; 27 123 }