From f7ba502005d6376328e1e2591d70973d4f1d6b15 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 12 Oct 2022 02:26:40 -0700 Subject: feat(tvix/eval): implement builtins.currentSystem This commit implements builtins.currentSystem, by capturing the cargo environment variable `TARGET` and exposing it to rustc as `TVIX_CURRENT_SYSTEM` so it can be inserted into the source code using `env!()`. The resulting value needs to be massaged a bit, since it is an "LLVM triple". The current code should work for all the platforms for which cppnix works (thanks qyliss for generating the list!). It does *not* reject all of the triples that cppnix's configure.ac rejects -- it is much more forgiving. We can tighten this up in a future commit. Signed-off-by: Adam Joseph Change-Id: I947f504b2af5a7fee8cf0cb301421d2fc9174ce1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6986 Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/builtins/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tvix/eval/src/builtins') diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 2209edd962ae..25d00070e936 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -663,6 +663,8 @@ fn placeholders() -> Vec { }, )] } +// we set TVIX_CURRENT_SYSTEM in build.rs +pub const CURRENT_PLATFORM: &str = env!("TVIX_CURRENT_SYSTEM"); fn builtins_set() -> NixAttrs { let mut map: BTreeMap = BTreeMap::new(); @@ -673,6 +675,11 @@ fn builtins_set() -> NixAttrs { Value::String("2.3-compat-tvix-0.1".into()), ); + map.insert( + "currentSystem".into(), + crate::systems::llvm_triple_to_nix_double(CURRENT_PLATFORM).into(), + ); + let mut add_builtins = |builtins: Vec| { for builtin in builtins { map.insert(builtin.name().into(), Value::Builtin(builtin)); -- cgit 1.4.1