mirror of
https://github.com/roc-lang/roc.git
synced 2024-10-26 18:28:43 +03:00
Run build script instead of zig build on big sur
This commit is contained in:
parent
6f9e64f2ea
commit
a4d3f96f25
2
.envrc
2
.envrc
@ -93,7 +93,7 @@ use_nix() {
|
||||
fi
|
||||
|
||||
log_status "use nix: updating cache"
|
||||
nix-shell --pure "${drv}" --show-trace --run "$(join_args "$direnv" dump bash)" > "${dump}"
|
||||
nix-shell "${drv}" --show-trace --run "$(join_args "$direnv" dump bash)" > "${dump}"
|
||||
if [[ "${?}" -ne 0 ]] || [[ ! -f "${dump}" ]] || ! grep -q IN_NIX_SHELL "${dump}"; then
|
||||
rm -rf "${wd}"
|
||||
fail "use nix: was not able to update the cache of the environment. Please run 'direnv reload' to try again."
|
||||
|
5
compiler/builtins/bitcode/build.sh
Executable file
5
compiler/builtins/bitcode/build.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euxo pipefail
|
||||
|
||||
zig build-obj src/main.zig -O ReleaseFast -femit-llvm-ir=builtins.ll -femit-bin=builtins.o --strip
|
@ -10,28 +10,36 @@ use std::str;
|
||||
fn main() {
|
||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||
|
||||
let big_sur_path = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib";
|
||||
let use_build_script = Path::new(big_sur_path).exists();
|
||||
|
||||
// "." is relative to where "build.rs" is
|
||||
let build_script_dir_path = fs::canonicalize(Path::new(".")).unwrap();
|
||||
let bitcode_path = build_script_dir_path.join("bitcode");
|
||||
|
||||
let src_obj_path = bitcode_path.join("builtins.o");
|
||||
let src_obj = src_obj_path.to_str().expect("Invalid src object path");
|
||||
println!("Compiling zig object to: {}", src_obj);
|
||||
|
||||
let dest_ir_path = bitcode_path.join("builtins.ll");
|
||||
let dest_ir = dest_ir_path.to_str().expect("Invalid dest ir path");
|
||||
|
||||
if use_build_script {
|
||||
println!("Compiling zig object & ir to: {} and {}", src_obj, dest_ir);
|
||||
run_command_with_no_args(&bitcode_path, "./build.sh");
|
||||
} else {
|
||||
println!("Compiling zig object to: {}", src_obj);
|
||||
run_command(&bitcode_path, "zig", &["build", "object", "-Drelease=true"]);
|
||||
|
||||
println!("Compiling ir to: {}", dest_ir);
|
||||
run_command(&bitcode_path, "zig", &["build", "ir", "-Drelease=true"]);
|
||||
}
|
||||
|
||||
let dest_obj_path = Path::new(&out_dir).join("builtins.o");
|
||||
let dest_obj = dest_obj_path.to_str().expect("Invalid dest object path");
|
||||
println!("Moving zig object to: {}", dest_obj);
|
||||
|
||||
run_command(&bitcode_path, "mv", &[src_obj, dest_obj]);
|
||||
|
||||
let dest_ir_path = bitcode_path.join("builtins.ll");
|
||||
let dest_ir = dest_ir_path.to_str().expect("Invalid dest ir path");
|
||||
println!("Compiling ir to: {}", dest_ir);
|
||||
|
||||
run_command(&bitcode_path, "zig", &["build", "ir", "-Drelease=true"]);
|
||||
|
||||
let dest_bc_path = bitcode_path.join("builtins.bc");
|
||||
let dest_bc = dest_bc_path.to_str().expect("Invalid dest bc path");
|
||||
println!("Compiling bitcode to: {}", dest_bc);
|
||||
@ -78,6 +86,26 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn run_command_with_no_args<P: AsRef<Path>>(path: P, command_str: &str)
|
||||
{
|
||||
let output_result = Command::new(OsStr::new(&command_str))
|
||||
.current_dir(path)
|
||||
.output();
|
||||
match output_result {
|
||||
Ok(output) => match output.status.success() {
|
||||
true => (),
|
||||
false => {
|
||||
let error_str = match str::from_utf8(&output.stderr) {
|
||||
Ok(stderr) => stderr.to_string(),
|
||||
Err(_) => format!("Failed to run \"{}\"", command_str),
|
||||
};
|
||||
panic!("{} failed: {}", command_str, error_str);
|
||||
}
|
||||
},
|
||||
Err(reason) => panic!("{} failed: {}", command_str, reason),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_zig_files(dir: &Path, cb: &dyn Fn(&Path)) -> io::Result<()> {
|
||||
if dir.is_dir() {
|
||||
for entry in fs::read_dir(dir)? {
|
||||
|
32
shell.nix
32
shell.nix
@ -4,15 +4,18 @@ let
|
||||
splitSystem = builtins.split "-" builtins.currentSystem;
|
||||
currentArch = builtins.elemAt splitSystem 0;
|
||||
currentOS = builtins.elemAt splitSystem 2;
|
||||
in with {
|
||||
in
|
||||
with {
|
||||
# Look here for information about how pin version of nixpkgs
|
||||
# → https://nixos.wiki/wiki/FAQ/Pinning_Nixpkgs
|
||||
pkgs = import (builtins.fetchGit {
|
||||
name = "nixpkgs-2021-04-23";
|
||||
pkgs = import (
|
||||
builtins.fetchGit {
|
||||
# name = "nixpkgs-2021-04-23";
|
||||
url = "https://github.com/nixos/nixpkgs/";
|
||||
ref = "refs/heads/nixpkgs-unstable";
|
||||
rev = "8d0340aee5caac3807c58ad7fa4ebdbbdd9134d6";
|
||||
}) { };
|
||||
}
|
||||
) {};
|
||||
|
||||
isMacOS = currentOS == "darwin";
|
||||
isLinux = currentOS == "linux";
|
||||
@ -53,13 +56,6 @@ let
|
||||
else
|
||||
[];
|
||||
|
||||
nixos-env =
|
||||
if isLinux && builtins.pathExists /etc/nixos/configuration.nix then
|
||||
{ XDG_DATA_DIRS = "/run/opengl-driver/share:$XDG_DATA_DIRS";
|
||||
}
|
||||
else
|
||||
{ };
|
||||
|
||||
llvmPkgs = pkgs.llvmPackages_10;
|
||||
zig = import ./nix/zig.nix { inherit pkgs isMacOS isAarch64; };
|
||||
inputs = [
|
||||
@ -91,13 +87,16 @@ let
|
||||
# (import ./nix/zls.nix { inherit pkgs zig; })
|
||||
];
|
||||
|
||||
in mkShell (nixos-env // {
|
||||
in
|
||||
mkShell (
|
||||
{
|
||||
buildInputs = inputs ++ darwin-inputs ++ linux-inputs;
|
||||
|
||||
# Additional Env vars
|
||||
LLVM_SYS_100_PREFIX = "${llvmPkgs.llvm}";
|
||||
LD_LIBRARY_PATH = stdenv.lib.makeLibraryPath
|
||||
([
|
||||
(
|
||||
[
|
||||
pkg-config
|
||||
stdenv.cc.cc.lib
|
||||
llvmPkgs.libcxx
|
||||
@ -106,11 +105,12 @@ in mkShell (nixos-env // {
|
||||
libffi
|
||||
ncurses
|
||||
zlib
|
||||
] ++ linux-inputs);
|
||||
] ++ linux-inputs
|
||||
);
|
||||
|
||||
# Aliases don't work cross shell, so we do this
|
||||
shellHook = ''
|
||||
export PATH="$PATH:$PWD/nix/bin"
|
||||
'';
|
||||
})
|
||||
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user