From e9c23144a3713880adcb72a29d39e74c39853e05 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 13 Feb 2025 12:21:34 +0200 Subject: [PATCH] pref: add Preferences.vroot_file/1 (done here, without using it, to ease the bootstrapping of the cheaders extraction, that will follow next) --- vlib/v/pref/default.v | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vlib/v/pref/default.v b/vlib/v/pref/default.v index b3fb62323c7ca3..6b2d63534b04bd 100644 --- a/vlib/v/pref/default.v +++ b/vlib/v/pref/default.v @@ -377,3 +377,11 @@ pub fn (p &Preferences) vcross_compiler_name() string { } return 'cc' } + +// vroot_file reads the given file, given a path relative to @VROOT . +// Its goal is to give all backends a shared infrastructure to read their own static preludes (like C headers etc), +// without each having to implement their own way of lookup/embedding/caching them. +pub fn (mut p Preferences) vroot_file(path string) string { + full_path := os.join_path(p.vroot, path) + return os.read_file(full_path) or { '/* missing vroot content of path: ${full_path} */' } +}