mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 15:59:20 +03:00
Get rid of some Unix-specific slashes
This commit is contained in:
parent
a775c94596
commit
ab12ddf85f
@ -364,7 +364,7 @@ pub fn examples_dir(dir_name: &str) -> PathBuf {
|
||||
|
||||
// Descend into examples/{dir_name}
|
||||
path.push("examples");
|
||||
path.push(dir_name);
|
||||
path.extend(dir_name.split("/")); // Make slashes cross-platform
|
||||
|
||||
path
|
||||
}
|
||||
@ -386,7 +386,7 @@ pub fn fixtures_dir(dir_name: &str) -> PathBuf {
|
||||
path.push("cli");
|
||||
path.push("tests");
|
||||
path.push("fixtures");
|
||||
path.push(dir_name);
|
||||
path.extend(dir_name.split("/")); // Make slashes cross-platform
|
||||
|
||||
path
|
||||
}
|
||||
|
@ -25,7 +25,8 @@ fn main() {
|
||||
|
||||
fn write_subs_for_module(module_id: ModuleId, filename: &str) {
|
||||
// Tell Cargo that if the given file changes, to rerun this build script.
|
||||
println!("cargo:rerun-if-changed=../builtins/roc/{}", filename);
|
||||
let filepath = PathBuf::from("..").join("builtins").join("roc").join(filename);
|
||||
println!("cargo:rerun-if-changed={}", filepath.to_str().unwrap());
|
||||
|
||||
let arena = Bump::new();
|
||||
let src_dir = PathBuf::from(".");
|
||||
|
@ -2,6 +2,7 @@ use roc_builtins::bitcode;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
use wasi_libc_sys::{WASI_COMPILER_RT_PATH, WASI_LIBC_PATH};
|
||||
@ -9,11 +10,6 @@ use wasi_libc_sys::{WASI_COMPILER_RT_PATH, WASI_LIBC_PATH};
|
||||
const PLATFORM_FILENAME: &str = "wasm_test_platform";
|
||||
const OUT_DIR_VAR: &str = "TEST_GEN_OUT";
|
||||
|
||||
const LINKING_TEST_HOST_SOURCE: &str = "src/helpers/wasm_linking_test_host.zig";
|
||||
const LINKING_TEST_IMPORT_SOURCE: &str = "src/helpers/wasm_linking_host_imports.zig";
|
||||
const LINKING_TEST_HOST_WASM: &str = "build/wasm_linking_test_host.wasm";
|
||||
const LINKING_TEST_HOST_NATIVE: &str = "build/wasm_linking_test_host";
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
if feature_is_enabled("gen-wasm") {
|
||||
@ -23,13 +19,29 @@ fn main() {
|
||||
}
|
||||
|
||||
fn build_wasm_linking_test_host() {
|
||||
println!("cargo:rerun-if-changed={}", LINKING_TEST_HOST_SOURCE);
|
||||
println!("cargo:rerun-if-changed={}", LINKING_TEST_IMPORT_SOURCE);
|
||||
let host_source_path = PathBuf::from("src")
|
||||
.join("helpers")
|
||||
.join("wasm_linking_test_host.zig");
|
||||
|
||||
let import_source_path = PathBuf::from("src")
|
||||
.join("helpers")
|
||||
.join("wasm_linking_host_imports.zig");
|
||||
|
||||
let host_wasm_path = PathBuf::from("build").join("wasm_linking_test_host.wasm");
|
||||
let host_native_path = PathBuf::from("build").join("wasm_linking_test_host");
|
||||
|
||||
let host_source: &str = host_source_path.to_str().unwrap();
|
||||
let import_source: &str = import_source_path.to_str().unwrap();
|
||||
let host_wasm: &str = host_wasm_path.to_str().unwrap();
|
||||
let host_native: &str = host_native_path.to_str().unwrap();
|
||||
|
||||
println!("cargo:rerun-if-changed={}", host_source);
|
||||
println!("cargo:rerun-if-changed={}", import_source);
|
||||
|
||||
fs::create_dir("build").unwrap();
|
||||
|
||||
if Path::new(LINKING_TEST_HOST_WASM).exists() {
|
||||
fs::remove_file(LINKING_TEST_HOST_WASM).unwrap();
|
||||
if Path::new(host_wasm).exists() {
|
||||
fs::remove_file(host_wasm).unwrap();
|
||||
}
|
||||
|
||||
Command::new("zig")
|
||||
@ -37,28 +49,30 @@ fn build_wasm_linking_test_host() {
|
||||
"build-obj",
|
||||
"-target",
|
||||
"wasm32-freestanding-musl",
|
||||
LINKING_TEST_HOST_SOURCE,
|
||||
&format!("-femit-bin={}", LINKING_TEST_HOST_WASM),
|
||||
host_source,
|
||||
&format!("-femit-bin={}", host_wasm),
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
let host_obj = "build/wasm_linking_test_host.o";
|
||||
let host_obj_path = PathBuf::from("build").join("wasm_linking_test_host.o");
|
||||
let host_obj = host_obj_path.to_str().unwrap();
|
||||
Command::new("zig")
|
||||
.args([
|
||||
"build-obj",
|
||||
LINKING_TEST_HOST_SOURCE,
|
||||
&format!("-femit-bin={}", host_obj),
|
||||
host_source,
|
||||
&format!("-femit-bin={}", &host_obj),
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
let import_obj = "build/wasm_linking_host_imports.o";
|
||||
let import_obj_path = PathBuf::from("build").join("wasm_linking_host_imports.o");
|
||||
let import_obj = import_obj_path.to_str().unwrap();
|
||||
Command::new("zig")
|
||||
.args([
|
||||
"build-obj",
|
||||
LINKING_TEST_IMPORT_SOURCE,
|
||||
&format!("-femit-bin={}", import_obj),
|
||||
import_source,
|
||||
&format!("-femit-bin={}", &import_obj),
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
@ -68,31 +82,38 @@ fn build_wasm_linking_test_host() {
|
||||
"build-exe",
|
||||
host_obj,
|
||||
import_obj,
|
||||
&format!("-femit-bin={}", LINKING_TEST_HOST_NATIVE),
|
||||
&format!("-femit-bin={}", host_native),
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn build_wasm_test_host() {
|
||||
let source_path = format!("src/helpers/{}.c", PLATFORM_FILENAME);
|
||||
println!("cargo:rerun-if-changed={}", source_path);
|
||||
let mut source_path = PathBuf::new()
|
||||
.join("src")
|
||||
.join("helpers")
|
||||
.join(PLATFORM_FILENAME);
|
||||
source_path.set_extension("c");
|
||||
println!("cargo:rerun-if-changed={}", source_path.to_str().unwrap());
|
||||
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
println!("cargo:rustc-env={}={}", OUT_DIR_VAR, out_dir);
|
||||
|
||||
// Create an object file with relocations
|
||||
let platform_path = build_wasm_platform(&out_dir, &source_path);
|
||||
let platform_path = build_wasm_platform(&out_dir, source_path.to_str().unwrap());
|
||||
|
||||
let mut outfile = PathBuf::from(out_dir).join(PLATFORM_FILENAME);
|
||||
outfile.set_extension(".o");
|
||||
|
||||
Command::new(&zig_executable())
|
||||
.args([
|
||||
"wasm-ld",
|
||||
bitcode::BUILTINS_WASM32_OBJ_PATH,
|
||||
&platform_path,
|
||||
platform_path.to_str().unwrap(),
|
||||
WASI_COMPILER_RT_PATH,
|
||||
WASI_LIBC_PATH,
|
||||
"-o",
|
||||
&format!("{}/{}.o", out_dir, PLATFORM_FILENAME),
|
||||
outfile.to_str().unwrap(),
|
||||
"--no-entry",
|
||||
"--relocatable",
|
||||
])
|
||||
@ -107,8 +128,9 @@ fn zig_executable() -> String {
|
||||
}
|
||||
}
|
||||
|
||||
fn build_wasm_platform(out_dir: &str, source_path: &str) -> String {
|
||||
let platform_path = format!("{}/{}.o", out_dir, PLATFORM_FILENAME);
|
||||
fn build_wasm_platform(out_dir: &str, source_path: &str) -> PathBuf {
|
||||
let mut outfile = PathBuf::from(out_dir).join(PLATFORM_FILENAME);
|
||||
outfile.set_extension(".o");
|
||||
|
||||
Command::new(&zig_executable())
|
||||
.args([
|
||||
@ -117,12 +139,12 @@ fn build_wasm_platform(out_dir: &str, source_path: &str) -> String {
|
||||
"wasm32-wasi",
|
||||
"-lc",
|
||||
source_path,
|
||||
&format!("-femit-bin={}", &platform_path),
|
||||
&format!("-femit-bin={}", outfile.to_str().unwrap()),
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
platform_path
|
||||
outfile
|
||||
}
|
||||
|
||||
fn feature_is_enabled(feature_name: &str) -> bool {
|
||||
|
@ -26,7 +26,7 @@ fn main() {
|
||||
.args([
|
||||
"wasm-ld",
|
||||
bitcode::BUILTINS_WASM32_OBJ_PATH,
|
||||
&platform_obj,
|
||||
platform_obj.to_str().unwrap(),
|
||||
WASI_COMPILER_RT_PATH,
|
||||
WASI_LIBC_PATH,
|
||||
"-o",
|
||||
@ -46,8 +46,9 @@ fn zig_executable() -> String {
|
||||
}
|
||||
}
|
||||
|
||||
fn build_wasm_platform(out_dir: &str, source_path: &str) -> String {
|
||||
let platform_obj = format!("{}/{}.o", out_dir, PLATFORM_FILENAME);
|
||||
fn build_wasm_platform(out_dir: &str, source_path: &str) -> PathBuf {
|
||||
let mut platform_obj = PathBuf::from(out_dir).join(PLATFORM_FILENAME);
|
||||
platform_obj.set_extension("o");
|
||||
|
||||
Command::new(&zig_executable())
|
||||
.args([
|
||||
@ -56,7 +57,7 @@ fn build_wasm_platform(out_dir: &str, source_path: &str) -> String {
|
||||
"wasm32-wasi",
|
||||
"-lc",
|
||||
source_path,
|
||||
&format!("-femit-bin={}", &platform_obj),
|
||||
&format!("-femit-bin={}", platform_obj.to_str().unwrap()),
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user