From d3bc358bbc41b8913eb3ffebe93d33cfe5fc11b1 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 10 Jun 2024 10:58:25 +0300 Subject: docs(tvix/docs/TODO): document crate2nix for WASM attempts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I tried moving web/tvixbolt to tvix/tvixbolt, and adding it to the cargo workspace. I then made `crates =` in `default.nix` a function accepting `pkgs` (so we can pass in another nixpkgs for some invocations), and then constructed another nixpkgs and crates instance like this: ``` pkgs-wasm = (import pkgs.path { localSystem = localSystem; crossSystem = { system = localSystem; rustc.config = "wasm32-unknown-unknown"; }; } crates-wasm = (crates pkgs-wasm); tvixbolt-test = crates-wasm.workspaceMembers.tvixbolt.build; ``` … leading to the architecture build failures described in the TODO. Change-Id: I32112d75f8c098d9810ca52b2d07cd76fae8d8d7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11777 Reviewed-by: flokli Reviewed-by: Ilan Joselevich Autosubmit: flokli Tested-by: BuildkiteCI --- tvix/docs/src/TODO.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tvix/docs/src/TODO.md') diff --git a/tvix/docs/src/TODO.md b/tvix/docs/src/TODO.md index c686f8ab64eb..20ad07eb2505 100644 --- a/tvix/docs/src/TODO.md +++ b/tvix/docs/src/TODO.md @@ -25,6 +25,32 @@ sure noone is working on this, or has some specific design in mind already. with a different level of `--strict`, but the toplevel doc-comment suggests its generic? +### crate2nix for WASM +Most of Tvix is living inside a `//tvix` cargo workspace, and we use `crate2nix` +as a build system, to get crate-level build granularity (and caching), keeping +compile times somewhat manageable. + +In the future, for Store/Build, we want to build some more web frontends, +exposing some data by calling to the API. Being able to write this in Rust, +and reusing most of our existing code dealing with the data structures would +be preferred. + +However, using the crate2nix tooling in combination with compiling for WASM is +a bumpy ride (and `//web.tvixbolt` works around this by using +`rustPlatform.buildRustPackage` instead, which invokes cargo inside a FOD): + +`buildRustCrate` in nixpkgs (which is used by `crate2nix` under the hood) +doesn't allow specifying another `--target` explicitly, but relies on the cross +machinery in nixpkgs exclusively. + +`doc/languages-frameworks/rust.section.md` suggests it should be a matter of +re-instantiating nixpkgs for `wasm32-unknown-unknown`, but that's no recognized +as a valid architecture. +The suggested alternative, setting only `rustc.config` to it seems to get us +further, but the `Crate.nix` logic for detecting arch-conditional crates doesn't +seem to cover that case, and tries to build crates (`cpufeatures` for `sha{1,2}`) +which are supposed to be skipped. + ## Perf - String Contexts currently do a lot of indirections (edef) (NixString -> NixStringInner -> HashSet[element] -> NixContextElement -> String -> data) -- cgit 1.4.1