From 9508cd7275dd92ba055b316cbbb19e8212c90933 Mon Sep 17 00:00:00 2001 From: David Gonzalez Martin Date: Tue, 24 Jun 2025 21:56:46 -0600 Subject: [PATCH] Ability to set CMAKE_PREFIX_PATH from env vars --- src/compiler.bbb | 12 ++++++++++++ src/compiler.cpp | 10 ++++++++++ src/lib.cpp | 6 ++++++ src/lib.hpp | 1 + 4 files changed, 29 insertions(+) diff --git a/src/compiler.bbb b/src/compiler.bbb index a28c1e1..ac95311 100644 --- a/src/compiler.bbb +++ b/src/compiler.bbb @@ -77,6 +77,8 @@ O = bits u32 [extern] memcpy = fn [cc(c)] (destination: &u8, source: &u8, byte_count: u64) &u8; [extern] exit = fn [cc(c)] (exit_code: int) noreturn; +[extern] getenv = fn [cc(c)] (env: &u8) &u8; + [extern] realpath = fn [cc(c)] (source_path: &u8, resolved_path: &u8) &u8; [extern] mkdir = fn [cc(c)] (path: &u8, mode: mode_t) int; @@ -18356,6 +18358,16 @@ compile_file = fn (arena: &Arena, compile_options: CompileFile, envp: &&u8) []u8 .value = CMAKE_PREFIX_PATH, }; + if (is_compiler) + { + >cmake_prefix_path_cstr = getenv("CMAKE_PREFIX_PATH"); + if (cmake_prefix_path_cstr) + { + >cmake_prefix_path_value = c_string_to_slice(cmake_prefix_path_cstr); + cmake_prefix_path_definition.value = cmake_prefix_path_value; + } + } + >objects = [ output_object_path ][..]; >c_abi_library = "build/libc_abi.a"; >llvm_bindings_library = "build/libllvm_bindings.a"; diff --git a/src/compiler.cpp b/src/compiler.cpp index 729b640..94e0624 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -221,6 +221,16 @@ fn String compile_file(Arena* arena, Compile options) .value = cmake_prefix_path, }; + if (is_compiler) + { + auto cmake_prefix_path_cstr = os_get_environment_variable("CMAKE_PREFIX_PATH"); + if (cmake_prefix_path_cstr) + { + auto cmake_prefix_path_string = c_string_to_slice(cmake_prefix_path_cstr); + cmake_prefix_path_definition.value = cmake_prefix_path_string; + } + } + String objects[] = { output_object_path, }; diff --git a/src/lib.cpp b/src/lib.cpp index fba49b4..3fe3b1c 100644 --- a/src/lib.cpp +++ b/src/lib.cpp @@ -225,3 +225,9 @@ Execution os_execute(Arena* arena, Slice arguments, Slice arguments, Slice environment, ExecuteOptions options); +char* os_get_environment_variable(const char* env);