diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index 39084a1e2f..8e2b98c5b9 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -122,6 +122,18 @@ fn link_linux( host_input_path: &Path, dest_filename: &Path, ) -> io::Result { + let libcrt_path = if Path::new("/usr/lib/x86_64-linux-gnu").exists() { + Path::new("/usr/lib/x86_64-linux-gnu") + } else { + Path::new("/usr/lib") + }; + let libgcc_path = if Path::new("/lib/x86_64-linux-gnu/libgcc_s.so.1").exists() { + Path::new("/lib/x86_64-linux-gnu/libgcc_s.so.1") + } else if Path::new("/usr/lib/x86_64-linux-gnu/libgcc_s.so.1").exists() { + Path::new("/usr/lib/x86_64-linux-gnu/libgcc_s.so.1") + } else { + Path::new("/usr/lib/libgcc_s.so.1") + }; // NOTE: order of arguments to `ld` matters here! // The `-l` flags should go after the `.o` arguments Command::new("ld") @@ -130,9 +142,9 @@ fn link_linux( .args(&[ "-arch", arch_str(target), - "/usr/lib/x86_64-linux-gnu/crti.o", - "/usr/lib/x86_64-linux-gnu/crtn.o", - "/usr/lib/x86_64-linux-gnu/Scrt1.o", + libcrt_path.join("crti.o").to_str().unwrap(), + libcrt_path.join("crtn.o").to_str().unwrap(), + libcrt_path.join("Scrt1.o").to_str().unwrap(), "-dynamic-linker", "/lib64/ld-linux-x86-64.so.2", // Inputs @@ -149,7 +161,7 @@ fn link_linux( "-lc_nonshared", "-lc++", "-lunwind", - // "-lgcc", // TODO will eventually need compiler_rt from gcc or something - see https://github.com/rtfeldman/roc/pull/554#discussion_r496370840 + libgcc_path.to_str().unwrap(), // Output "-o", binary_path.to_str().unwrap(), // app diff --git a/compiler/load/src/docs.rs b/compiler/load/src/docs.rs index 7dd777962e..ac1dd3036f 100644 --- a/compiler/load/src/docs.rs +++ b/compiler/load/src/docs.rs @@ -350,8 +350,14 @@ pub fn load( let arena = Bump::new(); // Reserve one CPU for the main thread, and let all the others be eligible - // to spawn workers. - let num_workers = num_cpus::get() - 1; + // to spawn workers. We use .max(2) to enforce that we always + // end up with at least 1 worker - since (.max(2) - 1) will + // always return a number that's at least 1. Using + // .max(2) on the initial number of CPUs instead of + // doing .max(1) on the entire expression guards against + // num_cpus returning 0, while also avoiding wrapping + // unsigned subtraction overflow. + let num_workers = num_cpus::get().max(2) - 1; let mut worker_arenas = bumpalo::collections::Vec::with_capacity_in(num_workers, &arena); diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 4bd0060d03..7d55993c8c 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -823,8 +823,15 @@ fn load<'a>( where { // Reserve one CPU for the main thread, and let all the others be eligible - // to spawn workers. - let num_workers = num_cpus::get() - 1; + // to spawn workers. We use .max(2) to enforce that we always + // end up with at least 1 worker - since (.max(2) - 1) will + // always return a number that's at least 1. Using + // .max(2) on the initial number of CPUs instead of + // doing .max(1) on the entire expression guards against + // num_cpus returning 0, while also avoiding wrapping + // unsigned subtraction overflow. + let num_workers = num_cpus::get().max(2) - 1; + let worker_arenas = arena.alloc(bumpalo::collections::Vec::with_capacity_in( num_workers, arena, diff --git a/examples/.gitignore b/examples/.gitignore index 789188bb46..c66fcb3fdd 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1,2 +1,3 @@ app host.o +c_host.o diff --git a/examples/quicksort/platform/src/lib.rs b/examples/quicksort/platform/src/lib.rs index 3af3cee432..ddbadca30f 100644 --- a/examples/quicksort/platform/src/lib.rs +++ b/examples/quicksort/platform/src/lib.rs @@ -6,7 +6,7 @@ extern "C" { fn quicksort(list: RocList) -> RocList; } -const NUM_NUMS: usize = 1_000_000; +const NUM_NUMS: usize = 10_000; #[no_mangle] pub fn rust_main() -> isize { @@ -14,7 +14,7 @@ pub fn rust_main() -> isize { let mut nums = Vec::with_capacity(NUM_NUMS); for index in 0..nums.capacity() { - let num = index as i64 % 12345; + let num = index as i64 % 123; nums.push(num); } diff --git a/roc_std/src/lib.rs b/roc_std/src/lib.rs index 7b50cd2a0b..1888770ef8 100644 --- a/roc_std/src/lib.rs +++ b/roc_std/src/lib.rs @@ -71,7 +71,7 @@ impl RocList { let value = *self.get_storage_ptr(); // NOTE doesn't work with elements of 16 or more bytes - match usize::cmp(&0, &value) { + match isize::cmp(&(value as isize), &0) { Equal => Some(Storage::ReadOnly), Less => Some(Storage::Refcounted(value)), Greater => Some(Storage::Capacity(value)),