fixing windows cargo build errors

This commit is contained in:
Anton-4 2022-02-28 13:48:11 +01:00
parent 16e568be76
commit 784894bb8f
No known key found for this signature in database
GPG key ID: C954D6E0F9C0ABFD
7 changed files with 72 additions and 29 deletions

14
Cargo.lock generated
View file

@ -1162,7 +1162,7 @@ checksum = "1d428afc93ad288f6dffc1fa5f4a78201ad2eec33c5a522e51c181009eb09061"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"dynasm", "dynasm",
"memmap2 0.5.0", "memmap2 0.5.3",
] ]
[[package]] [[package]]
@ -2018,9 +2018,9 @@ dependencies = [
[[package]] [[package]]
name = "memmap2" name = "memmap2"
version = "0.5.0" version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4647a11b578fead29cdbb34d4adef8dd3dc35b876c9c6d5240d83f205abfe96e" checksum = "057a3db23999c867821a7a59feb06a578fcb03685e983dff90daf9e7d24ac08f"
dependencies = [ dependencies = [
"libc", "libc",
] ]
@ -3195,8 +3195,10 @@ dependencies = [
"roc_target", "roc_target",
"roc_types", "roc_types",
"roc_unify", "roc_unify",
"slab",
"snafu", "snafu",
"ven_graph", "ven_graph",
"winapi",
] ]
[[package]] [[package]]
@ -3495,7 +3497,7 @@ dependencies = [
"bumpalo", "bumpalo",
"clap 3.0.0-beta.5", "clap 3.0.0-beta.5",
"iced-x86", "iced-x86",
"memmap2 0.5.0", "memmap2 0.5.3",
"object 0.26.2", "object 0.26.2",
"roc_build", "roc_build",
"roc_collections", "roc_collections",
@ -3825,7 +3827,7 @@ checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088"
[[package]] [[package]]
name = "rustyline" name = "rustyline"
version = "9.1.1" version = "9.1.1"
source = "git+https://github.com/rtfeldman/rustyline?tag=v9.1.1#7053ae0fe0ee710d38ed5845dd979113382994dc" source = "git+https://github.com/rtfeldman/rustyline?rev=e74333c#e74333c0d618896b88175bf06645108f996fe6d0"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cfg-if 1.0.0", "cfg-if 1.0.0",
@ -3848,7 +3850,7 @@ dependencies = [
[[package]] [[package]]
name = "rustyline-derive" name = "rustyline-derive"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/rtfeldman/rustyline?tag=v9.1.1#7053ae0fe0ee710d38ed5845dd979113382994dc" source = "git+https://github.com/rtfeldman/rustyline?rev=e74333c#e74333c0d618896b88175bf06645108f996fe6d0"
dependencies = [ dependencies = [
"quote", "quote",
"syn", "syn",

View file

@ -21,10 +21,16 @@ roc_target = { path = "../compiler/roc_target" }
roc_error_macros = { path = "../error_macros" } roc_error_macros = { path = "../error_macros" }
arrayvec = "0.7.2" arrayvec = "0.7.2"
bumpalo = { version = "3.8.0", features = ["collections"] } bumpalo = { version = "3.8.0", features = ["collections"] }
libc = "0.2.106"
page_size = "0.4.2" page_size = "0.4.2"
snafu = { version = "0.6.10", features = ["backtraces"] } snafu = { version = "0.6.10", features = ["backtraces"] }
ven_graph = { path = "../vendor/pathfinding" } ven_graph = { path = "../vendor/pathfinding" }
slab = "0.4.5"
[dev-dependencies] [dev-dependencies]
indoc = "1.0.3" indoc = "1.0.3"
[target.'cfg(windows)'.dependencies]
winapi = "0.3.9"
[target.'cfg(unix)'.dependencies]
libc = "0.2.106"

View file

@ -10,12 +10,10 @@
/// ///
/// Pages also use the node value 0 (all 0 bits) to mark nodes as unoccupied. /// Pages also use the node value 0 (all 0 bits) to mark nodes as unoccupied.
/// This is important for performance. /// This is important for performance.
use libc::{MAP_ANONYMOUS, MAP_PRIVATE, PROT_READ, PROT_WRITE};
use std::any::type_name; use std::any::type_name;
use std::ffi::c_void; use std::ffi::c_void;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem::{align_of, size_of, MaybeUninit}; use std::mem::{align_of, size_of, MaybeUninit};
use std::ptr::null;
pub const NODE_BYTES: usize = 32; pub const NODE_BYTES: usize = 32;
@ -108,14 +106,30 @@ impl Pool {
// addresses from the OS which will be lazily translated into // addresses from the OS which will be lazily translated into
// physical memory one 4096-byte page at a time, once we actually // physical memory one 4096-byte page at a time, once we actually
// try to read or write in that page's address range. // try to read or write in that page's address range.
libc::mmap( #[cfg(unix)]{
null::<c_void>() as *mut c_void, use libc::{MAP_ANONYMOUS, MAP_PRIVATE, PROT_READ, PROT_WRITE};
bytes_to_mmap,
PROT_READ | PROT_WRITE, libc::mmap(
MAP_PRIVATE | MAP_ANONYMOUS, std::ptr::null_mut(),
0, bytes_to_mmap,
0, PROT_READ | PROT_WRITE,
) MAP_PRIVATE | MAP_ANONYMOUS,
0,
0,
)
}
#[cfg(windows)]{
use winapi::um::memoryapi::{VirtualAlloc};
use winapi::um::winnt::{MEM_COMMIT, MEM_RESERVE};
use winapi::um::winnt::{PAGE_READWRITE};
VirtualAlloc(
std::ptr::null_mut(),
bytes_to_mmap,
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE,
)
}
} as *mut [MaybeUninit<u8>; NODE_BYTES]; } as *mut [MaybeUninit<u8>; NODE_BYTES];
// This is our actual capacity, in nodes. // This is our actual capacity, in nodes.
@ -230,10 +244,22 @@ impl<T> std::ops::IndexMut<NodeId<T>> for Pool {
impl Drop for Pool { impl Drop for Pool {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
libc::munmap( #[cfg(unix)]{
self.nodes as *mut c_void, libc::munmap(
NODE_BYTES * self.capacity as usize, self.nodes as *mut c_void,
); NODE_BYTES * self.capacity as usize,
);
}
#[cfg(windows)]{
use winapi::um::memoryapi::{VirtualFree};
use winapi::um::winnt::{MEM_RELEASE};
VirtualFree(
self.nodes as *mut c_void,
NODE_BYTES * self.capacity as usize,
MEM_RELEASE
);
}
} }
} }
} }

View file

@ -50,12 +50,17 @@ fn main() {
); );
// OBJECT FILES // OBJECT FILES
#[cfg(windows)]
const BUILTINS_HOST_FILE: &str = "builtins-host.obj";
#[cfg(not(windows))]
const BUILTINS_HOST_FILE: &str = "builtins-host.o";
generate_object_file( generate_object_file(
&bitcode_path, &bitcode_path,
"BUILTINS_HOST_O", "BUILTINS_HOST_O",
"object", "object",
"builtins-host.o", BUILTINS_HOST_FILE,
); );
generate_object_file( generate_object_file(

View file

@ -24,7 +24,7 @@ roc_collections = { path = "../compiler/collections" }
bumpalo = { version = "3.8.0", features = ["collections"] } bumpalo = { version = "3.8.0", features = ["collections"] }
clap = { version = "= 3.0.0-beta.5", default-features = false, features = ["std", "color", "suggestions"] } clap = { version = "= 3.0.0-beta.5", default-features = false, features = ["std", "color", "suggestions"] }
iced-x86 = { version = "1.15.0", default-features = false, features = ["std", "decoder", "op_code_info", "instr_info"] } iced-x86 = { version = "1.15.0", default-features = false, features = ["std", "decoder", "op_code_info", "instr_info"] }
memmap2 = "0.5.0" memmap2 = "0.5.3"
object = { version = "0.26.2", features = ["read", "write"] } object = { version = "0.26.2", features = ["read", "write"] }
serde = { version = "1.0.130", features = ["derive"] } serde = { version = "1.0.130", features = ["derive"] }
bincode = "1.3.3" bincode = "1.3.3"

View file

@ -20,7 +20,6 @@ use std::io;
use std::io::{BufReader, BufWriter}; use std::io::{BufReader, BufWriter};
use std::mem; use std::mem;
use std::os::raw::c_char; use std::os::raw::c_char;
use std::os::unix::fs::PermissionsExt;
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
@ -1627,9 +1626,14 @@ fn surgery_impl(
let flushing_data_duration = flushing_data_start.elapsed().unwrap(); let flushing_data_duration = flushing_data_start.elapsed().unwrap();
// Make sure the final executable has permision to execute. // Make sure the final executable has permision to execute.
let mut perms = fs::metadata(out_filename)?.permissions(); // TODO windows alternative?
perms.set_mode(perms.mode() | 0o111); #[cfg(target_family = "unix")]
fs::set_permissions(out_filename, perms)?; {
use std::os::unix::fs::PermissionsExt;
let mut perms = fs::metadata(out_filename)?.permissions();
perms.set_mode(perms.mode() | 0o111);
fs::set_permissions(out_filename, perms)?;
}
let total_duration = total_start.elapsed().unwrap(); let total_duration = total_start.elapsed().unwrap();

View file

@ -10,8 +10,8 @@ bumpalo = {version = "3.8.0", features = ["collections"]}
const_format = "0.2.22" const_format = "0.2.22"
inkwell = {path = "../vendor/inkwell"} inkwell = {path = "../vendor/inkwell"}
libloading = {version = "0.7.1"} libloading = {version = "0.7.1"}
rustyline = {git = "https://github.com/rtfeldman/rustyline", tag = "v9.1.1"} rustyline = {git = "https://github.com/rtfeldman/rustyline", rev = "e74333c"}
rustyline-derive = {git = "https://github.com/rtfeldman/rustyline", tag = "v9.1.1"} rustyline-derive = {git = "https://github.com/rtfeldman/rustyline", rev = "e74333c"}
target-lexicon = "0.12.2" target-lexicon = "0.12.2"
roc_build = {path = "../compiler/build"} roc_build = {path = "../compiler/build"}