mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Merge remote-tracking branch 'origin/trunk' into windows-linking
This commit is contained in:
commit
19159d170a
45 changed files with 1849 additions and 991 deletions
|
@ -10,6 +10,7 @@ roc_collections = { path = "../collections" }
|
|||
roc_region = { path = "../region" }
|
||||
roc_module = { path = "../module" }
|
||||
roc_target = { path = "../roc_target" }
|
||||
roc_utils = { path = "../../utils" }
|
||||
lazy_static = "1.4.0"
|
||||
|
||||
[build-dependencies]
|
||||
|
|
|
@ -2608,10 +2608,10 @@ test "getScalarUnsafe" {
|
|||
}
|
||||
|
||||
pub fn strCloneTo(
|
||||
string: RocStr,
|
||||
ptr: [*]u8,
|
||||
offset: usize,
|
||||
extra_offset: usize,
|
||||
string: RocStr,
|
||||
) callconv(.C) usize {
|
||||
const WIDTH: usize = @sizeOf(RocStr);
|
||||
if (string.isSmallStr()) {
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::ffi::OsStr;
|
|||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::str;
|
||||
|
||||
|
@ -53,19 +54,9 @@ fn main() {
|
|||
#[cfg(not(windows))]
|
||||
const BUILTINS_HOST_FILE: &str = "builtins-host.o";
|
||||
|
||||
generate_object_file(
|
||||
&bitcode_path,
|
||||
"BUILTINS_HOST_O",
|
||||
"object",
|
||||
BUILTINS_HOST_FILE,
|
||||
);
|
||||
generate_object_file(&bitcode_path, "object", BUILTINS_HOST_FILE);
|
||||
|
||||
generate_object_file(
|
||||
&bitcode_path,
|
||||
"BUILTINS_WASM32_O",
|
||||
"wasm32-object",
|
||||
"builtins-wasm32.o",
|
||||
);
|
||||
generate_object_file(&bitcode_path, "wasm32-object", "builtins-wasm32.o");
|
||||
|
||||
copy_zig_builtins_to_target_dir(&bitcode_path);
|
||||
|
||||
|
@ -84,21 +75,10 @@ fn main() {
|
|||
.expect("Failed to delete temp dir zig_cache_dir.");
|
||||
}
|
||||
|
||||
fn generate_object_file(
|
||||
bitcode_path: &Path,
|
||||
env_var_name: &str,
|
||||
zig_object: &str,
|
||||
object_file_name: &str,
|
||||
) {
|
||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||
|
||||
let dest_obj_path = Path::new(&out_dir).join(object_file_name);
|
||||
fn generate_object_file(bitcode_path: &Path, zig_object: &str, object_file_name: &str) {
|
||||
let dest_obj_path = get_lib_dir().join(object_file_name);
|
||||
let dest_obj = dest_obj_path.to_str().expect("Invalid dest object path");
|
||||
|
||||
// set the variable (e.g. BUILTINS_HOST_O) that is later used in
|
||||
// `compiler/builtins/src/bitcode.rs` to load the object file
|
||||
println!("cargo:rustc-env={}={}", env_var_name, dest_obj);
|
||||
|
||||
let src_obj_path = bitcode_path.join(object_file_name);
|
||||
let src_obj = src_obj_path.to_str().expect("Invalid src object path");
|
||||
|
||||
|
@ -146,20 +126,29 @@ fn generate_bc_file(bitcode_path: &Path, zig_object: &str, file_name: &str) {
|
|||
);
|
||||
}
|
||||
|
||||
fn copy_zig_builtins_to_target_dir(bitcode_path: &Path) {
|
||||
// To enable roc to find the zig biultins, we want them to be moved to a folder next to the roc executable.
|
||||
// So if <roc_folder>/roc is the executable. The zig files will be in <roc_folder>/lib/*.zig
|
||||
|
||||
pub fn get_lib_dir() -> PathBuf {
|
||||
// Currently we have the OUT_DIR variable which points to `/target/debug/build/roc_builtins-*/out/`.
|
||||
// So we just need to shed a 3 of the outer layers to get `/target/debug/` and then add `lib`.
|
||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||
let target_profile_dir = Path::new(&out_dir)
|
||||
|
||||
let lib_path = Path::new(&out_dir)
|
||||
.parent()
|
||||
.and_then(|path| path.parent())
|
||||
.and_then(|path| path.parent())
|
||||
.unwrap()
|
||||
.join("lib");
|
||||
|
||||
// create dir of it does not exist
|
||||
fs::create_dir_all(lib_path.clone()).expect("Failed to make lib dir.");
|
||||
|
||||
lib_path
|
||||
}
|
||||
|
||||
fn copy_zig_builtins_to_target_dir(bitcode_path: &Path) {
|
||||
// To enable roc to find the zig biultins, we want them to be moved to a folder next to the roc executable.
|
||||
// So if <roc_folder>/roc is the executable. The zig files will be in <roc_folder>/lib/*.zig
|
||||
let target_profile_dir = get_lib_dir();
|
||||
|
||||
let zig_src_dir = bitcode_path.join("src");
|
||||
|
||||
cp_unless_zig_cache(&zig_src_dir, &target_profile_dir).unwrap_or_else(|err| {
|
||||
|
|
|
@ -1,16 +1,29 @@
|
|||
use roc_module::symbol::Symbol;
|
||||
use roc_target::TargetInfo;
|
||||
use roc_utils::get_lib_path;
|
||||
use std::ops::Index;
|
||||
|
||||
pub const BUILTINS_HOST_OBJ_PATH: &str = env!(
|
||||
"BUILTINS_HOST_O",
|
||||
"Env var BUILTINS_HOST_O not found. Is there a problem with the build script?"
|
||||
);
|
||||
pub fn get_builtins_host_obj_path() -> String {
|
||||
let builtins_host_path = get_lib_path()
|
||||
.expect("Failed to find lib dir.")
|
||||
.join("builtins-host.o");
|
||||
|
||||
pub const BUILTINS_WASM32_OBJ_PATH: &str = env!(
|
||||
"BUILTINS_WASM32_O",
|
||||
"Env var BUILTINS_WASM32_O not found. Is there a problem with the build script?"
|
||||
);
|
||||
builtins_host_path
|
||||
.into_os_string()
|
||||
.into_string()
|
||||
.expect("Failed to convert builtins_host_path to str")
|
||||
}
|
||||
|
||||
pub fn get_builtins_wasm32_obj_path() -> String {
|
||||
let builtins_wasm32_path = get_lib_path()
|
||||
.expect("Failed to find lib dir.")
|
||||
.join("builtins-wasm32.o");
|
||||
|
||||
builtins_wasm32_path
|
||||
.into_os_string()
|
||||
.into_string()
|
||||
.expect("Failed to convert builtins_wasm32_path to str")
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Copy, Clone)]
|
||||
pub struct IntrinsicName {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue