From 68984b59c98b4b72742478120b2a9760a9dc6e11 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 19 Jun 2023 23:44:02 -0400 Subject: [PATCH 01/21] Update `roc build --target` to add more triples --- crates/cli/src/lib.rs | 76 +++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 5fc5f88108a..e87d5406ef3 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -29,7 +29,7 @@ use std::path::{Path, PathBuf}; use std::process; use std::time::Instant; use strum::{EnumIter, IntoEnumIterator, IntoStaticStr}; -use target_lexicon::BinaryFormat; +use target_lexicon::{Aarch64Architecture, BinaryFormat}; use target_lexicon::{ Architecture, Environment, OperatingSystem, Triple, Vendor, X86_32Architecture, }; @@ -1281,44 +1281,75 @@ pub enum Target { #[strum(serialize = "system")] #[default] System, - #[strum(serialize = "linux32")] - Linux32, - #[strum(serialize = "linux64")] - Linux64, - #[strum(serialize = "windows64")] - Windows64, - #[strum(serialize = "wasm32")] + #[strum(serialize = "linux-x86-32")] + LinuxX32, + #[strum(serialize = "linux-x86-64")] + LinuxX64, + #[strum(serialize = "linux-arm-64")] + LinuxArm64, + #[strum(serialize = "macos-x86-64")] + MacX64, + #[strum(serialize = "macos-arm-64")] + MacArm64, + #[strum(serialize = "windows-x86-64")] + WinX64, + #[strum(serialize = "wasm-32")] Wasm32, } +const MACOS: OperatingSystem = OperatingSystem::MacOSX { + major: 12, + minor: 0, + patch: 0, +}; + impl Target { pub fn to_triple(self) -> Triple { - use Target::*; - match self { - System => Triple::host(), - Linux32 => Triple { + Target::System => Triple::host(), + Target::LinuxX32 => Triple { architecture: Architecture::X86_32(X86_32Architecture::I386), vendor: Vendor::Unknown, operating_system: OperatingSystem::Linux, - environment: Environment::Musl, + environment: Environment::Unknown, binary_format: BinaryFormat::Elf, }, - Linux64 => Triple { + Target::LinuxX64 => Triple { architecture: Architecture::X86_64, vendor: Vendor::Unknown, operating_system: OperatingSystem::Linux, - environment: Environment::Musl, + environment: Environment::Unknown, binary_format: BinaryFormat::Elf, }, - Windows64 => Triple { + Target::LinuxArm64 => Triple { + architecture: Architecture::Aarch64(Aarch64Architecture::Aarch64), + vendor: Vendor::Unknown, + operating_system: OperatingSystem::Linux, + environment: Environment::Unknown, + binary_format: BinaryFormat::Elf, + }, + Target::WinX64 => Triple { architecture: Architecture::X86_64, vendor: Vendor::Unknown, operating_system: OperatingSystem::Windows, environment: Environment::Gnu, binary_format: BinaryFormat::Coff, }, - Wasm32 => Triple { + Target::MacX64 => Triple { + architecture: Architecture::X86_64, + vendor: Vendor::Apple, + operating_system: MACOS, + environment: Environment::Unknown, + binary_format: BinaryFormat::Macho, + }, + Target::MacArm64 => Triple { + architecture: Architecture::Aarch64(Aarch64Architecture::Aarch64), + vendor: Vendor::Apple, + operating_system: MACOS, + environment: Environment::Unknown, + binary_format: BinaryFormat::Macho, + }, + Target::Wasm32 => Triple { architecture: Architecture::Wasm32, vendor: Vendor::Unknown, operating_system: OperatingSystem::Wasi, @@ -1347,10 +1378,13 @@ impl std::str::FromStr for Target { fn from_str(string: &str) -> Result { match string { "system" => Ok(Target::System), - "linux32" => Ok(Target::Linux32), - "linux64" => Ok(Target::Linux64), - "windows64" => Ok(Target::Windows64), - "wasm32" => Ok(Target::Wasm32), + "linux-x86-32" => Ok(Target::LinuxX32), + "linux-x86-64" => Ok(Target::LinuxX64), + "linux-arm-64" => Ok(Target::LinuxArm64), + "macos-x86-64" => Ok(Target::MacX64), + "macos-arm-64" => Ok(Target::MacArm64), + "windows-x86-64" => Ok(Target::WinX64), + "wasm-32" => Ok(Target::Wasm32), _ => Err(format!("Roc does not know how to compile to {}", string)), } } From d5802c1cbefdb3c1972cc15d84f6cfb429f17dc2 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 20 Jun 2023 07:47:48 -0400 Subject: [PATCH 02/21] Update docs and tests to use --target wasm-32 --- crates/cli/tests/cli_run.rs | 2 +- examples/nodejs-interop/wasm/README.md | 2 +- examples/nodejs-interop/wasm/platform/host.zig | 2 +- examples/platform-switching/web-assembly-platform/README.md | 4 ++-- examples/platform-switching/web-assembly-platform/host.zig | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index 826c8c146b4..2510bc32079 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -1098,7 +1098,7 @@ mod cli_run { use super::{concatcp, run_roc, CMD_BUILD, TARGET_FLAG}; let mut flags = flags.to_vec(); - flags.push(concatcp!(TARGET_FLAG, "=wasm32")); + flags.push(concatcp!(TARGET_FLAG, "=wasm-32")); let compile_out = run_roc( [CMD_BUILD, file.to_str().unwrap()] diff --git a/examples/nodejs-interop/wasm/README.md b/examples/nodejs-interop/wasm/README.md index 26bdf6f37e9..8eb01d187d1 100644 --- a/examples/nodejs-interop/wasm/README.md +++ b/examples/nodejs-interop/wasm/README.md @@ -5,7 +5,7 @@ This is an example of calling Roc code from [Node.js](https://nodejs.org/en/). You'll need to have [Zig](https://zig-lang.org) installed. Run this from the current directory: ``` -roc build --target=wasm32 +roc build --target=wasm-32 node hello.js ``` diff --git a/examples/nodejs-interop/wasm/platform/host.zig b/examples/nodejs-interop/wasm/platform/host.zig index 8e9c1d8610e..dc3f990ecd9 100644 --- a/examples/nodejs-interop/wasm/platform/host.zig +++ b/examples/nodejs-interop/wasm/platform/host.zig @@ -4,7 +4,7 @@ const RocStr = str.RocStr; comptime { if (builtin.target.cpu.arch != .wasm32) { - @compileError("This platform is for WebAssembly only. You need to pass `--target wasm32` to the Roc compiler."); + @compileError("This platform is for WebAssembly only. You need to pass `--target wasm-32` to the Roc compiler."); } } diff --git a/examples/platform-switching/web-assembly-platform/README.md b/examples/platform-switching/web-assembly-platform/README.md index b9d36b1b6ba..b8b8582360f 100644 --- a/examples/platform-switching/web-assembly-platform/README.md +++ b/examples/platform-switching/web-assembly-platform/README.md @@ -4,13 +4,13 @@ To run this website, we first compile the app that uses the Wasm platform: - If you use the nightly roc release: ```bash -./roc build --target=wasm32 examples/platform-switching/rocLovesWebAssembly.roc +./roc build --target=wasm-32 examples/platform-switching/rocLovesWebAssembly.roc ``` - If you start from the compiler source code: ```bash # Build roc compiler if you have not done so already cargo build -target/debug/roc build --target=wasm32 examples/platform-switching/rocLovesWebAssembly.roc +target/debug/roc build --target=wasm-32 examples/platform-switching/rocLovesWebAssembly.roc ``` We then move the file: ```bash diff --git a/examples/platform-switching/web-assembly-platform/host.zig b/examples/platform-switching/web-assembly-platform/host.zig index 8e9c1d8610e..dc3f990ecd9 100644 --- a/examples/platform-switching/web-assembly-platform/host.zig +++ b/examples/platform-switching/web-assembly-platform/host.zig @@ -4,7 +4,7 @@ const RocStr = str.RocStr; comptime { if (builtin.target.cpu.arch != .wasm32) { - @compileError("This platform is for WebAssembly only. You need to pass `--target wasm32` to the Roc compiler."); + @compileError("This platform is for WebAssembly only. You need to pass `--target wasm-32` to the Roc compiler."); } } From aeca4b328e378af8d7cad96c2f5da0dd04d3f7ee Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 20 Jun 2023 07:48:56 -0400 Subject: [PATCH 03/21] Make a single source of truth for target strings --- crates/cli/src/lib.rs | 122 +------------------- crates/cli/src/main.rs | 9 +- crates/compiler/roc_target/src/lib.rs | 160 +++++++++++++++++++++++--- 3 files changed, 151 insertions(+), 140 deletions(-) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index e87d5406ef3..d360a8e691b 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -20,6 +20,7 @@ use roc_load::{ExpectMetadata, Threading}; use roc_mono::ir::OptLevel; use roc_packaging::cache::RocCacheDir; use roc_packaging::tarball::Compression; +use roc_target::Target; use std::env; use std::ffi::{CString, OsStr, OsString}; use std::io; @@ -28,11 +29,8 @@ use std::os::raw::{c_char, c_int}; use std::path::{Path, PathBuf}; use std::process; use std::time::Instant; -use strum::{EnumIter, IntoEnumIterator, IntoStaticStr}; -use target_lexicon::{Aarch64Architecture, BinaryFormat}; -use target_lexicon::{ - Architecture, Environment, OperatingSystem, Triple, Vendor, X86_32Architecture, -}; +use strum::IntoEnumIterator; +use target_lexicon::{Architecture, Triple}; #[cfg(not(target_os = "linux"))] use tempfile::TempDir; @@ -1275,117 +1273,3 @@ fn run_wasm, S: AsRef<[u8]>>(wasm_path: &std::path::Path, fn run_wasm, S: AsRef<[u8]>>(_wasm_path: &std::path::Path, _args: I) { println!("Running wasm files is not supported on this target."); } - -#[derive(Debug, Copy, Clone, EnumIter, IntoStaticStr, PartialEq, Eq, Default)] -pub enum Target { - #[strum(serialize = "system")] - #[default] - System, - #[strum(serialize = "linux-x86-32")] - LinuxX32, - #[strum(serialize = "linux-x86-64")] - LinuxX64, - #[strum(serialize = "linux-arm-64")] - LinuxArm64, - #[strum(serialize = "macos-x86-64")] - MacX64, - #[strum(serialize = "macos-arm-64")] - MacArm64, - #[strum(serialize = "windows-x86-64")] - WinX64, - #[strum(serialize = "wasm-32")] - Wasm32, -} - -const MACOS: OperatingSystem = OperatingSystem::MacOSX { - major: 12, - minor: 0, - patch: 0, -}; - -impl Target { - pub fn to_triple(self) -> Triple { - match self { - Target::System => Triple::host(), - Target::LinuxX32 => Triple { - architecture: Architecture::X86_32(X86_32Architecture::I386), - vendor: Vendor::Unknown, - operating_system: OperatingSystem::Linux, - environment: Environment::Unknown, - binary_format: BinaryFormat::Elf, - }, - Target::LinuxX64 => Triple { - architecture: Architecture::X86_64, - vendor: Vendor::Unknown, - operating_system: OperatingSystem::Linux, - environment: Environment::Unknown, - binary_format: BinaryFormat::Elf, - }, - Target::LinuxArm64 => Triple { - architecture: Architecture::Aarch64(Aarch64Architecture::Aarch64), - vendor: Vendor::Unknown, - operating_system: OperatingSystem::Linux, - environment: Environment::Unknown, - binary_format: BinaryFormat::Elf, - }, - Target::WinX64 => Triple { - architecture: Architecture::X86_64, - vendor: Vendor::Unknown, - operating_system: OperatingSystem::Windows, - environment: Environment::Gnu, - binary_format: BinaryFormat::Coff, - }, - Target::MacX64 => Triple { - architecture: Architecture::X86_64, - vendor: Vendor::Apple, - operating_system: MACOS, - environment: Environment::Unknown, - binary_format: BinaryFormat::Macho, - }, - Target::MacArm64 => Triple { - architecture: Architecture::Aarch64(Aarch64Architecture::Aarch64), - vendor: Vendor::Apple, - operating_system: MACOS, - environment: Environment::Unknown, - binary_format: BinaryFormat::Macho, - }, - Target::Wasm32 => Triple { - architecture: Architecture::Wasm32, - vendor: Vendor::Unknown, - operating_system: OperatingSystem::Wasi, - environment: Environment::Unknown, - binary_format: BinaryFormat::Wasm, - }, - } - } -} - -impl From<&Target> for Triple { - fn from(target: &Target) -> Self { - target.to_triple() - } -} - -impl std::fmt::Display for Target { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", Into::<&'static str>::into(self)) - } -} - -impl std::str::FromStr for Target { - type Err = String; - - fn from_str(string: &str) -> Result { - match string { - "system" => Ok(Target::System), - "linux-x86-32" => Ok(Target::LinuxX32), - "linux-x86-64" => Ok(Target::LinuxX64), - "linux-arm-64" => Ok(Target::LinuxArm64), - "macos-x86-64" => Ok(Target::MacX64), - "macos-arm-64" => Ok(Target::MacArm64), - "windows-x86-64" => Ok(Target::WinX64), - "wasm-32" => Ok(Target::Wasm32), - _ => Err(format!("Roc does not know how to compile to {}", string)), - } - } -} diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 93fb5750d7f..cbebcb5f387 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -2,10 +2,10 @@ use roc_build::link::LinkType; use roc_build::program::{check_file, CodeGenBackend}; use roc_cli::{ - build_app, format, test, BuildConfig, FormatMode, Target, CMD_BUILD, CMD_CHECK, CMD_DEV, - CMD_DOCS, CMD_EDIT, CMD_FORMAT, CMD_GEN_STUB_LIB, CMD_GLUE, CMD_REPL, CMD_RUN, CMD_TEST, - CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_NO_LINK, FLAG_TARGET, - FLAG_TIME, GLUE_DIR, GLUE_SPEC, ROC_FILE, + build_app, format, test, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK, CMD_DEV, CMD_DOCS, + CMD_EDIT, CMD_FORMAT, CMD_GEN_STUB_LIB, CMD_GLUE, CMD_REPL, CMD_RUN, CMD_TEST, CMD_VERSION, + DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_NO_LINK, FLAG_TARGET, FLAG_TIME, + GLUE_DIR, GLUE_SPEC, ROC_FILE, }; use roc_docs::generate_docs_html; use roc_error_macros::user_error; @@ -13,6 +13,7 @@ use roc_gen_dev::AssemblyBackendMode; use roc_gen_llvm::llvm::build::LlvmBackendMode; use roc_load::{LoadingProblem, Threading}; use roc_packaging::cache::{self, RocCacheDir}; +use roc_target::Target; use std::fs::{self, FileType}; use std::io; use std::path::{Path, PathBuf}; diff --git a/crates/compiler/roc_target/src/lib.rs b/crates/compiler/roc_target/src/lib.rs index 126ad118e32..269e2ddf10b 100644 --- a/crates/compiler/roc_target/src/lib.rs +++ b/crates/compiler/roc_target/src/lib.rs @@ -3,7 +3,8 @@ // See github.com/roc-lang/roc/issues/800 for discussion of the large_enum_variant check. #![allow(clippy::large_enum_variant)] -use strum_macros::{EnumCount, EnumIter}; +use strum_macros::{EnumCount, EnumIter, IntoStaticStr}; +use target_lexicon::Triple; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum OperatingSystem { @@ -159,56 +160,181 @@ impl From for Architecture { } } -pub const WASM_TARGET_STR: &str = "wasm32"; -pub const LINUX_X86_64_TARGET_STR: &str = "linux-x86_64"; -pub const LINUX_ARM64_TARGET_STR: &str = "linux-arm64"; -pub const MACOS_ARM64_TARGET_STR: &str = "macos-arm64"; -pub const MACOS_X86_64_TARGET_STR: &str = "macos-x86_64"; -pub const WINDOWS_X86_64_TARGET_STR: &str = "windows-x86_64"; -pub const WINDOWS_X86_32_TARGET_STR: &str = "windows-x86_32"; -pub const WIDNOWS_ARM64_TARGET_STR: &str = "windows-arm64"; +#[derive(Debug, Copy, Clone, EnumIter, IntoStaticStr, PartialEq, Eq, Default)] +pub enum Target { + #[strum(serialize = "system")] + #[default] + System, + #[strum(serialize = "linux-x86-32")] + LinuxX32, + #[strum(serialize = "linux-x86-64")] + LinuxX64, + #[strum(serialize = "linux-arm-64")] + LinuxArm64, + #[strum(serialize = "macos-x86-64")] + MacX64, + #[strum(serialize = "macos-arm-64")] + MacArm64, + #[strum(serialize = "windows-x86-32")] + WinX32, + #[strum(serialize = "windows-x86-64")] + WinX64, + #[strum(serialize = "windows-arm-64")] + WinArm64, + #[strum(serialize = "wasm-32")] + Wasm32, +} + +const MACOS: target_lexicon::OperatingSystem = target_lexicon::OperatingSystem::MacOSX { + major: 12, + minor: 0, + patch: 0, +}; + +impl Target { + pub fn to_triple(self) -> Triple { + use target_lexicon::*; + + match self { + Target::System => Triple::host(), + Target::LinuxX32 => Triple { + architecture: Architecture::X86_32(X86_32Architecture::I386), + vendor: Vendor::Unknown, + operating_system: OperatingSystem::Linux, + environment: Environment::Unknown, + binary_format: BinaryFormat::Elf, + }, + Target::LinuxX64 => Triple { + architecture: Architecture::X86_64, + vendor: Vendor::Unknown, + operating_system: OperatingSystem::Linux, + environment: Environment::Unknown, + binary_format: BinaryFormat::Elf, + }, + Target::LinuxArm64 => Triple { + architecture: Architecture::Aarch64(Aarch64Architecture::Aarch64), + vendor: Vendor::Unknown, + operating_system: OperatingSystem::Linux, + environment: Environment::Unknown, + binary_format: BinaryFormat::Elf, + }, + Target::WinX32 => Triple { + architecture: Architecture::X86_32(X86_32Architecture::I386), + vendor: Vendor::Unknown, + operating_system: OperatingSystem::Windows, + environment: Environment::Gnu, + binary_format: BinaryFormat::Coff, + }, + Target::WinX64 => Triple { + architecture: Architecture::X86_64, + vendor: Vendor::Unknown, + operating_system: OperatingSystem::Windows, + environment: Environment::Gnu, + binary_format: BinaryFormat::Coff, + }, + Target::WinArm64 => Triple { + architecture: Architecture::Aarch64(Aarch64Architecture::Aarch64), + vendor: Vendor::Unknown, + operating_system: OperatingSystem::Windows, + environment: Environment::Gnu, + binary_format: BinaryFormat::Coff, + }, + Target::MacX64 => Triple { + architecture: Architecture::X86_64, + vendor: Vendor::Apple, + operating_system: MACOS, + environment: Environment::Unknown, + binary_format: BinaryFormat::Macho, + }, + Target::MacArm64 => Triple { + architecture: Architecture::Aarch64(Aarch64Architecture::Aarch64), + vendor: Vendor::Apple, + operating_system: MACOS, + environment: Environment::Unknown, + binary_format: BinaryFormat::Macho, + }, + Target::Wasm32 => Triple { + architecture: Architecture::Wasm32, + vendor: Vendor::Unknown, + operating_system: OperatingSystem::Wasi, + environment: Environment::Unknown, + binary_format: BinaryFormat::Wasm, + }, + } + } +} + +impl From<&Target> for Triple { + fn from(target: &Target) -> Self { + target.to_triple() + } +} + +impl std::fmt::Display for Target { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{}", Into::<&'static str>::into(self)) + } +} + +impl std::str::FromStr for Target { + type Err = String; + + fn from_str(string: &str) -> Result { + match string { + "system" => Ok(Target::System), + "linux-x86-32" => Ok(Target::LinuxX32), + "linux-x86-64" => Ok(Target::LinuxX64), + "linux-arm-64" => Ok(Target::LinuxArm64), + "macos-x86-64" => Ok(Target::MacX64), + "macos-arm-64" => Ok(Target::MacArm64), + "windows-x86-64" => Ok(Target::WinX64), + "wasm-32" => Ok(Target::Wasm32), + _ => Err(format!("Roc does not know how to compile to {}", string)), + } + } +} pub fn get_target_triple_str(target: &target_lexicon::Triple) -> Option<&'static str> { match target { target_lexicon::Triple { architecture: target_lexicon::Architecture::Wasm32, .. - } => Some(WASM_TARGET_STR), + } => Some(Target::Wasm32.into()), target_lexicon::Triple { operating_system: target_lexicon::OperatingSystem::Linux, architecture: target_lexicon::Architecture::X86_64, .. - } => Some(LINUX_X86_64_TARGET_STR), + } => Some(Target::LinuxX64.into()), target_lexicon::Triple { operating_system: target_lexicon::OperatingSystem::Linux, architecture: target_lexicon::Architecture::Aarch64(_), .. - } => Some(LINUX_ARM64_TARGET_STR), + } => Some(Target::LinuxArm64.into()), target_lexicon::Triple { operating_system: target_lexicon::OperatingSystem::Darwin, architecture: target_lexicon::Architecture::Aarch64(_), .. - } => Some(MACOS_ARM64_TARGET_STR), + } => Some(Target::MacArm64.into()), target_lexicon::Triple { operating_system: target_lexicon::OperatingSystem::Darwin, architecture: target_lexicon::Architecture::X86_64, .. - } => Some(MACOS_X86_64_TARGET_STR), + } => Some(Target::MacX64.into()), target_lexicon::Triple { operating_system: target_lexicon::OperatingSystem::Windows, architecture: target_lexicon::Architecture::X86_64, .. - } => Some(WINDOWS_X86_64_TARGET_STR), + } => Some(Target::WinX64.into()), target_lexicon::Triple { operating_system: target_lexicon::OperatingSystem::Windows, architecture: target_lexicon::Architecture::X86_32(_), .. - } => Some(WINDOWS_X86_32_TARGET_STR), + } => Some(Target::WinX32.into()), target_lexicon::Triple { operating_system: target_lexicon::OperatingSystem::Windows, architecture: target_lexicon::Architecture::Aarch64(_), .. - } => Some(WIDNOWS_ARM64_TARGET_STR), + } => Some(Target::WinArm64.into()), _ => None, } } From 80c3334a1855a3274474bed45603adcf2ae72f13 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 20 Jun 2023 07:49:49 -0400 Subject: [PATCH 04/21] clippy --- crates/packaging/src/https.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/packaging/src/https.rs b/crates/packaging/src/https.rs index bfe02aaa3fb..3ef428de5f2 100644 --- a/crates/packaging/src/https.rs +++ b/crates/packaging/src/https.rs @@ -13,7 +13,7 @@ use crate::tarball::Compression; // let's try to avoid doing that. const BROTLI_BUFFER_BYTES: usize = 8 * 1_000_000; // MB -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub struct PackageMetadata<'a> { /// The BLAKE3 hash of the tarball's contents. Also the .tar filename on disk. pub content_hash: &'a str, @@ -45,7 +45,7 @@ const MISLEADING_CHARACTERS_IN_URL: [char; 5] = [ '\u{29F8}', // U+29F8 == ⧸ Big Solidus ]; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum UrlProblem { InvalidExtensionSuffix(String), MissingTarExt, From 1423d4f50f96e9216dbf3fa26c39d7f354b21667 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 20 Jun 2023 08:01:04 -0400 Subject: [PATCH 05/21] Use strum_macros::EnumString for Target --- crates/compiler/roc_target/src/lib.rs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/crates/compiler/roc_target/src/lib.rs b/crates/compiler/roc_target/src/lib.rs index 269e2ddf10b..4f4bafa91ce 100644 --- a/crates/compiler/roc_target/src/lib.rs +++ b/crates/compiler/roc_target/src/lib.rs @@ -3,7 +3,7 @@ // See github.com/roc-lang/roc/issues/800 for discussion of the large_enum_variant check. #![allow(clippy::large_enum_variant)] -use strum_macros::{EnumCount, EnumIter, IntoStaticStr}; +use strum_macros::{EnumCount, EnumIter, EnumString, IntoStaticStr}; use target_lexicon::Triple; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -160,7 +160,7 @@ impl From for Architecture { } } -#[derive(Debug, Copy, Clone, EnumIter, IntoStaticStr, PartialEq, Eq, Default)] +#[derive(Debug, Copy, Clone, EnumIter, EnumString, IntoStaticStr, PartialEq, Eq, Default)] pub enum Target { #[strum(serialize = "system")] #[default] @@ -276,24 +276,6 @@ impl std::fmt::Display for Target { } } -impl std::str::FromStr for Target { - type Err = String; - - fn from_str(string: &str) -> Result { - match string { - "system" => Ok(Target::System), - "linux-x86-32" => Ok(Target::LinuxX32), - "linux-x86-64" => Ok(Target::LinuxX64), - "linux-arm-64" => Ok(Target::LinuxArm64), - "macos-x86-64" => Ok(Target::MacX64), - "macos-arm-64" => Ok(Target::MacArm64), - "windows-x86-64" => Ok(Target::WinX64), - "wasm-32" => Ok(Target::Wasm32), - _ => Err(format!("Roc does not know how to compile to {}", string)), - } - } -} - pub fn get_target_triple_str(target: &target_lexicon::Triple) -> Option<&'static str> { match target { target_lexicon::Triple { From c046d417e1bf7e386ee17e3747ca6d3b27bac92c Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 20 Jun 2023 08:06:34 -0400 Subject: [PATCH 06/21] Go back to wasm32 --- crates/cli/tests/cli_run.rs | 2 +- crates/compiler/roc_target/src/lib.rs | 2 +- examples/nodejs-interop/wasm/README.md | 2 +- examples/nodejs-interop/wasm/platform/host.zig | 2 +- examples/platform-switching/web-assembly-platform/README.md | 4 ++-- examples/platform-switching/web-assembly-platform/host.zig | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index 2510bc32079..826c8c146b4 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -1098,7 +1098,7 @@ mod cli_run { use super::{concatcp, run_roc, CMD_BUILD, TARGET_FLAG}; let mut flags = flags.to_vec(); - flags.push(concatcp!(TARGET_FLAG, "=wasm-32")); + flags.push(concatcp!(TARGET_FLAG, "=wasm32")); let compile_out = run_roc( [CMD_BUILD, file.to_str().unwrap()] diff --git a/crates/compiler/roc_target/src/lib.rs b/crates/compiler/roc_target/src/lib.rs index 4f4bafa91ce..a33cb21497c 100644 --- a/crates/compiler/roc_target/src/lib.rs +++ b/crates/compiler/roc_target/src/lib.rs @@ -181,7 +181,7 @@ pub enum Target { WinX64, #[strum(serialize = "windows-arm-64")] WinArm64, - #[strum(serialize = "wasm-32")] + #[strum(serialize = "wasm32")] Wasm32, } diff --git a/examples/nodejs-interop/wasm/README.md b/examples/nodejs-interop/wasm/README.md index 8eb01d187d1..26bdf6f37e9 100644 --- a/examples/nodejs-interop/wasm/README.md +++ b/examples/nodejs-interop/wasm/README.md @@ -5,7 +5,7 @@ This is an example of calling Roc code from [Node.js](https://nodejs.org/en/). You'll need to have [Zig](https://zig-lang.org) installed. Run this from the current directory: ``` -roc build --target=wasm-32 +roc build --target=wasm32 node hello.js ``` diff --git a/examples/nodejs-interop/wasm/platform/host.zig b/examples/nodejs-interop/wasm/platform/host.zig index dc3f990ecd9..8e9c1d8610e 100644 --- a/examples/nodejs-interop/wasm/platform/host.zig +++ b/examples/nodejs-interop/wasm/platform/host.zig @@ -4,7 +4,7 @@ const RocStr = str.RocStr; comptime { if (builtin.target.cpu.arch != .wasm32) { - @compileError("This platform is for WebAssembly only. You need to pass `--target wasm-32` to the Roc compiler."); + @compileError("This platform is for WebAssembly only. You need to pass `--target wasm32` to the Roc compiler."); } } diff --git a/examples/platform-switching/web-assembly-platform/README.md b/examples/platform-switching/web-assembly-platform/README.md index b8b8582360f..b9d36b1b6ba 100644 --- a/examples/platform-switching/web-assembly-platform/README.md +++ b/examples/platform-switching/web-assembly-platform/README.md @@ -4,13 +4,13 @@ To run this website, we first compile the app that uses the Wasm platform: - If you use the nightly roc release: ```bash -./roc build --target=wasm-32 examples/platform-switching/rocLovesWebAssembly.roc +./roc build --target=wasm32 examples/platform-switching/rocLovesWebAssembly.roc ``` - If you start from the compiler source code: ```bash # Build roc compiler if you have not done so already cargo build -target/debug/roc build --target=wasm-32 examples/platform-switching/rocLovesWebAssembly.roc +target/debug/roc build --target=wasm32 examples/platform-switching/rocLovesWebAssembly.roc ``` We then move the file: ```bash diff --git a/examples/platform-switching/web-assembly-platform/host.zig b/examples/platform-switching/web-assembly-platform/host.zig index dc3f990ecd9..8e9c1d8610e 100644 --- a/examples/platform-switching/web-assembly-platform/host.zig +++ b/examples/platform-switching/web-assembly-platform/host.zig @@ -4,7 +4,7 @@ const RocStr = str.RocStr; comptime { if (builtin.target.cpu.arch != .wasm32) { - @compileError("This platform is for WebAssembly only. You need to pass `--target wasm-32` to the Roc compiler."); + @compileError("This platform is for WebAssembly only. You need to pass `--target wasm32` to the Roc compiler."); } } From e6c39792be63f12f2494bca3934d3b8e1ee19ce0 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 20 Jun 2023 08:10:15 -0400 Subject: [PATCH 07/21] Simplify --target CLI flag strings --- crates/compiler/roc_target/src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/compiler/roc_target/src/lib.rs b/crates/compiler/roc_target/src/lib.rs index a33cb21497c..e348db892cc 100644 --- a/crates/compiler/roc_target/src/lib.rs +++ b/crates/compiler/roc_target/src/lib.rs @@ -165,21 +165,21 @@ pub enum Target { #[strum(serialize = "system")] #[default] System, - #[strum(serialize = "linux-x86-32")] + #[strum(serialize = "linux-x32")] LinuxX32, - #[strum(serialize = "linux-x86-64")] + #[strum(serialize = "linux-x64")] LinuxX64, - #[strum(serialize = "linux-arm-64")] + #[strum(serialize = "linux-arm64")] LinuxArm64, - #[strum(serialize = "macos-x86-64")] + #[strum(serialize = "macos-x64")] MacX64, - #[strum(serialize = "macos-arm-64")] + #[strum(serialize = "macos-arm64")] MacArm64, - #[strum(serialize = "windows-x86-32")] + #[strum(serialize = "windows-x32")] WinX32, - #[strum(serialize = "windows-x86-64")] + #[strum(serialize = "windows-x64")] WinX64, - #[strum(serialize = "windows-arm-64")] + #[strum(serialize = "windows-arm64")] WinArm64, #[strum(serialize = "wasm32")] Wasm32, From f6a6bff72836606eec66041396344b4c328b5b39 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 20 Jun 2023 08:34:34 -0400 Subject: [PATCH 08/21] Improve backwards compatibility with old .rh files --- crates/compiler/build/src/program.rs | 33 +++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/crates/compiler/build/src/program.rs b/crates/compiler/build/src/program.rs index 09f8123f261..c02190ec6e9 100644 --- a/crates/compiler/build/src/program.rs +++ b/crates/compiler/build/src/program.rs @@ -807,7 +807,7 @@ fn build_loaded_file<'a>( }; // the preprocessed host is stored beside the platform's main.roc - let preprocessed_host_path = if linking_strategy == LinkingStrategy::Legacy { + let mut preprocessed_host_path = if linking_strategy == LinkingStrategy::Legacy { if let roc_target::OperatingSystem::Wasi = operating_system { // when compiling a wasm application, we implicitly assume here that the host is in zig // and has a file called "host.zig" @@ -835,9 +835,36 @@ fn build_loaded_file<'a>( None } else if is_platform_prebuilt { if !preprocessed_host_path.exists() { - invalid_prebuilt_platform(prebuilt_requested, preprocessed_host_path); + // Check for .rh and .o files using the old "x86_64" instead of the new "x64", for + // backwards compatibility with prebuilt platforms created before + // https://github.com/roc-lang/roc/pull/557 landed. + // + // Eventually (e.g. certainly after the end of 2023) this fixup can be removed. + let file_name = preprocessed_host_path + .file_name() + .unwrap_or_default() + .to_str() + .unwrap_or_default(); + + if file_name.ends_with("-x64.rh") || file_name.ends_with("-x64.o") { + let original_preprocessed_host_path = preprocessed_host_path.clone(); + + // Fixup the filename to the new format. + preprocessed_host_path = + preprocessed_host_path.with_file_name(file_name.replace("-x64.", "-x86_64.")); + + // Try again now that we've fixed the filename. + if !preprocessed_host_path.exists() { + // Report the error with the original path, not the attempted fixup. + invalid_prebuilt_platform(prebuilt_requested, original_preprocessed_host_path); + + std::process::exit(1); + } + } else { + invalid_prebuilt_platform(prebuilt_requested, preprocessed_host_path); - std::process::exit(1); + std::process::exit(1); + } } if linking_strategy == LinkingStrategy::Surgical { From eea43daeb6e48475caded99d87e3e84dd861aa8f Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 20 Jun 2023 09:23:08 -0400 Subject: [PATCH 09/21] Revert "Improve backwards compatibility with old .rh files" This reverts commit f6a6bff72836606eec66041396344b4c328b5b39. --- crates/compiler/build/src/program.rs | 33 +++------------------------- 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/crates/compiler/build/src/program.rs b/crates/compiler/build/src/program.rs index c02190ec6e9..09f8123f261 100644 --- a/crates/compiler/build/src/program.rs +++ b/crates/compiler/build/src/program.rs @@ -807,7 +807,7 @@ fn build_loaded_file<'a>( }; // the preprocessed host is stored beside the platform's main.roc - let mut preprocessed_host_path = if linking_strategy == LinkingStrategy::Legacy { + let preprocessed_host_path = if linking_strategy == LinkingStrategy::Legacy { if let roc_target::OperatingSystem::Wasi = operating_system { // when compiling a wasm application, we implicitly assume here that the host is in zig // and has a file called "host.zig" @@ -835,36 +835,9 @@ fn build_loaded_file<'a>( None } else if is_platform_prebuilt { if !preprocessed_host_path.exists() { - // Check for .rh and .o files using the old "x86_64" instead of the new "x64", for - // backwards compatibility with prebuilt platforms created before - // https://github.com/roc-lang/roc/pull/557 landed. - // - // Eventually (e.g. certainly after the end of 2023) this fixup can be removed. - let file_name = preprocessed_host_path - .file_name() - .unwrap_or_default() - .to_str() - .unwrap_or_default(); - - if file_name.ends_with("-x64.rh") || file_name.ends_with("-x64.o") { - let original_preprocessed_host_path = preprocessed_host_path.clone(); - - // Fixup the filename to the new format. - preprocessed_host_path = - preprocessed_host_path.with_file_name(file_name.replace("-x64.", "-x86_64.")); - - // Try again now that we've fixed the filename. - if !preprocessed_host_path.exists() { - // Report the error with the original path, not the attempted fixup. - invalid_prebuilt_platform(prebuilt_requested, original_preprocessed_host_path); - - std::process::exit(1); - } - } else { - invalid_prebuilt_platform(prebuilt_requested, preprocessed_host_path); + invalid_prebuilt_platform(prebuilt_requested, preprocessed_host_path); - std::process::exit(1); - } + std::process::exit(1); } if linking_strategy == LinkingStrategy::Surgical { From 23791d033c65c39b0944db9bc4d118a29a90164e Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Tue, 20 Jun 2023 16:12:21 +0200 Subject: [PATCH 10/21] build new nightlies --- .github/workflows/nightly_linux_x86_64.yml | 1 + .github/workflows/nightly_macos_apple_silicon.yml | 1 + .github/workflows/nightly_macos_x86_64.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/workflows/nightly_linux_x86_64.yml b/.github/workflows/nightly_linux_x86_64.yml index 6e506b8c82f..ec64047f940 100644 --- a/.github/workflows/nightly_linux_x86_64.yml +++ b/.github/workflows/nightly_linux_x86_64.yml @@ -1,4 +1,5 @@ on: + pull_request: workflow_dispatch: schedule: - cron: '0 9 * * *' diff --git a/.github/workflows/nightly_macos_apple_silicon.yml b/.github/workflows/nightly_macos_apple_silicon.yml index 3c0e70fd237..d9d699885ee 100644 --- a/.github/workflows/nightly_macos_apple_silicon.yml +++ b/.github/workflows/nightly_macos_apple_silicon.yml @@ -1,4 +1,5 @@ on: + pull_request: workflow_dispatch: schedule: - cron: '0 9 * * *' diff --git a/.github/workflows/nightly_macos_x86_64.yml b/.github/workflows/nightly_macos_x86_64.yml index 43e5ce868ff..5f0d0ad38ee 100644 --- a/.github/workflows/nightly_macos_x86_64.yml +++ b/.github/workflows/nightly_macos_x86_64.yml @@ -1,4 +1,5 @@ on: + pull_request: workflow_dispatch: schedule: - cron: '0 9 * * *' # 9=9am utc+0 From a6a522e8bf9de8bd8cbf8f20cf0b5be7569293b4 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Tue, 20 Jun 2023 16:47:28 +0200 Subject: [PATCH 11/21] skip tests on macos x86-64 --- .github/workflows/nightly_linux_x86_64.yml | 3 +-- .github/workflows/nightly_macos_apple_silicon.yml | 1 - .github/workflows/nightly_macos_x86_64.yml | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/nightly_linux_x86_64.yml b/.github/workflows/nightly_linux_x86_64.yml index ec64047f940..a71cb5a3852 100644 --- a/.github/workflows/nightly_linux_x86_64.yml +++ b/.github/workflows/nightly_linux_x86_64.yml @@ -1,5 +1,4 @@ on: - pull_request: workflow_dispatch: schedule: - cron: '0 9 * * *' @@ -8,7 +7,7 @@ name: Nightly Release Linux x86_64 jobs: build: - name: Rust tests, build and package nightly release + name: build and package nightly release runs-on: [self-hosted, i7-6700K] timeout-minutes: 90 steps: diff --git a/.github/workflows/nightly_macos_apple_silicon.yml b/.github/workflows/nightly_macos_apple_silicon.yml index d9d699885ee..3c0e70fd237 100644 --- a/.github/workflows/nightly_macos_apple_silicon.yml +++ b/.github/workflows/nightly_macos_apple_silicon.yml @@ -1,5 +1,4 @@ on: - pull_request: workflow_dispatch: schedule: - cron: '0 9 * * *' diff --git a/.github/workflows/nightly_macos_x86_64.yml b/.github/workflows/nightly_macos_x86_64.yml index 5f0d0ad38ee..a7dd534e009 100644 --- a/.github/workflows/nightly_macos_x86_64.yml +++ b/.github/workflows/nightly_macos_x86_64.yml @@ -18,7 +18,7 @@ jobs: run: ./ci/write_version.sh - name: execute rust tests - run: cargo test --release --locked -- --skip opaque_wrap_function --skip gen_list::bool_list_literal --skip platform_switching_swift --skip swift_ui --skip gen_str::str_append_scalar --skip gen_tags::phantom_polymorphic_record + run: cargo test --release --locked -- --skip opaque_wrap_function --skip gen_list::bool_list_literal --skip platform_switching_swift --skip swift_ui --skip gen_str::str_append_scalar --skip gen_tags::phantom_polymorphic_record --skip parse_letter_counts --skip hello_world # swift tests are skipped because of "Could not find or use auto-linked library 'swiftCompatibilityConcurrency'" on macos-11 x86_64 CI machine # this issue may be caused by using older versions of XCode From 84542b2b02c42c0e02cc0ba75ff7d81274159618 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 21 Jun 2023 08:46:40 -0400 Subject: [PATCH 12/21] Drop obsolete comment There's an open design question as to whether we want to commit to supporting this, so dropping the comment. --- crates/compiler/builtins/bitcode/build.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/compiler/builtins/bitcode/build.zig b/crates/compiler/builtins/bitcode/build.zig index a27d97bbb89..bbb24c4045e 100644 --- a/crates/compiler/builtins/bitcode/build.zig +++ b/crates/compiler/builtins/bitcode/build.zig @@ -25,7 +25,6 @@ pub fn build(b: *Builder) void { const host_target = b.standardTargetOptions(.{ .default_target = CrossTarget{ .cpu_model = .baseline, - // TODO allow for native target for maximum speed }, }); const linux32_target = makeLinux32Target(); From 44e48e141544260664a95d41563ec95d621c75e9 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 21 Jun 2023 08:47:38 -0400 Subject: [PATCH 13/21] Build Zig builtins for aarch64 --- crates/compiler/builtins/bitcode/bc/build.rs | 1 + crates/compiler/builtins/bitcode/build.zig | 18 +++++++++++++++--- crates/compiler/gen_llvm/src/llvm/build.rs | 9 ++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/compiler/builtins/bitcode/bc/build.rs b/crates/compiler/builtins/bitcode/bc/build.rs index 0d50904a8c3..130342b1bc6 100644 --- a/crates/compiler/builtins/bitcode/bc/build.rs +++ b/crates/compiler/builtins/bitcode/bc/build.rs @@ -35,6 +35,7 @@ fn main() { generate_bc_file(&bitcode_path, "ir-i386", "builtins-i386"); generate_bc_file(&bitcode_path, "ir-x86_64", "builtins-x86_64"); + generate_bc_file(&bitcode_path, "ir-aarch64", "builtins-aarch64"); generate_bc_file( &bitcode_path, "ir-windows-x86_64", diff --git a/crates/compiler/builtins/bitcode/build.zig b/crates/compiler/builtins/bitcode/build.zig index bbb24c4045e..7805c8410b4 100644 --- a/crates/compiler/builtins/bitcode/build.zig +++ b/crates/compiler/builtins/bitcode/build.zig @@ -28,14 +28,16 @@ pub fn build(b: *Builder) void { }, }); const linux32_target = makeLinux32Target(); - const linux64_target = makeLinux64Target(); + const linux_x64_target = makeLinuxX64Target(); + const linux_aarch64_target = makeLinuxAarch64Target(); const windows64_target = makeWindows64Target(); const wasm32_target = makeWasm32Target(); // LLVM IR generateLlvmIrFile(b, mode, host_target, main_path, "ir", "builtins-host"); generateLlvmIrFile(b, mode, linux32_target, main_path, "ir-i386", "builtins-i386"); - generateLlvmIrFile(b, mode, linux64_target, main_path, "ir-x86_64", "builtins-x86_64"); + generateLlvmIrFile(b, mode, linux_x64_target, main_path, "ir-x86_64", "builtins-x86_64"); + generateLlvmIrFile(b, mode, linux_aarch64_target, main_path, "ir-aarch64", "builtins-aarch64"); generateLlvmIrFile(b, mode, windows64_target, main_path, "ir-windows-x86_64", "builtins-windows-x86_64"); generateLlvmIrFile(b, mode, wasm32_target, main_path, "ir-wasm32", "builtins-wasm32"); @@ -102,7 +104,17 @@ fn makeLinux32Target() CrossTarget { return target; } -fn makeLinux64Target() CrossTarget { +fn makeLinuxAarch64Target() CrossTarget { + var target = CrossTarget.parse(.{}) catch unreachable; + + target.cpu_arch = std.Target.Cpu.Arch.aarch64; + target.os_tag = std.Target.Os.Tag.linux; + target.abi = std.Target.Abi.musl; + + return target; +} + +fn makeLinuxX64Target() CrossTarget { var target = CrossTarget.parse(.{}) catch unreachable; target.cpu_arch = std.Target.Cpu.Arch.x86_64; diff --git a/crates/compiler/gen_llvm/src/llvm/build.rs b/crates/compiler/gen_llvm/src/llvm/build.rs index c400bcce26a..bf0774e6ab5 100644 --- a/crates/compiler/gen_llvm/src/llvm/build.rs +++ b/crates/compiler/gen_llvm/src/llvm/build.rs @@ -51,7 +51,7 @@ use roc_std::RocDec; use roc_target::{PtrWidth, TargetInfo}; use std::convert::TryInto; use std::path::Path; -use target_lexicon::{Architecture, OperatingSystem, Triple}; +use target_lexicon::{Architecture, OperatingSystem, Triple, Aarch64Architecture}; use super::convert::{struct_type_from_union_layout, RocUnion}; use super::intrinsics::{ @@ -491,6 +491,13 @@ pub fn module_from_builtins<'ctx>( } => { include_bytes!("../../../builtins/bitcode/builtins-x86_64.bc") } + Triple { + architecture: Architecture::Aarch64(Aarch64Architecture::Aarch64), + operating_system: OperatingSystem::Linux, + .. + } => { + include_bytes!("../../../builtins/bitcode/builtins-aarch64.bc") + } Triple { architecture: Architecture::X86_64, operating_system: OperatingSystem::Windows, From 9a7877cf298690ff548d997e63fa83d599385789 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 21 Jun 2023 09:06:35 -0400 Subject: [PATCH 14/21] Force PIC when building Zig builtins --- crates/compiler/builtins/bitcode/build.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/compiler/builtins/bitcode/build.zig b/crates/compiler/builtins/bitcode/build.zig index 7805c8410b4..3a9091f5218 100644 --- a/crates/compiler/builtins/bitcode/build.zig +++ b/crates/compiler/builtins/bitcode/build.zig @@ -90,6 +90,7 @@ fn generateObjectFile( obj.strip = true; obj.target = target; obj.link_function_sections = true; + obj.force_pic = true; const obj_step = b.step(step_name, "Build object file for linking"); obj_step.dependOn(&obj.step); } From b8d723edcbe90333b48da099acd0bc5d85f76d7d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 21 Jun 2023 10:46:52 -0400 Subject: [PATCH 15/21] Don't use CodeModel::Large anymore This breaks certain use cases of building with --no-link and an aarch64 target and then linking with lld (via zig cc) (see "aarch64 linux target" thread on Zulip) Also it seems to be unnecessary in practice on LLVM 13, as the comment suggests! --- crates/compiler/build/src/target.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/crates/compiler/build/src/target.rs b/crates/compiler/build/src/target.rs index 6abe50cb349..3105170bf04 100644 --- a/crates/compiler/build/src/target.rs +++ b/crates/compiler/build/src/target.rs @@ -149,23 +149,13 @@ pub fn target_machine( init_arch(target); - let code_model = match target.architecture { - // LLVM 12 will not compile our programs without a large code model. - // The reason is not totally clear to me, but my guess is a few special-cases in - // llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (instructions) - // llvm/lib/Target/AArch64/AArch64Subtarget.cpp (GoT tables) - // Revisit when upgrading to LLVM 13. - Architecture::Aarch64(..) => CodeModel::Large, - _ => CodeModel::Default, - }; - Target::from_name(arch).unwrap().create_target_machine( &TargetTriple::create(target_triple_str(target)), "generic", - "", // TODO: this probably should be TargetMachine::get_host_cpu_features() to enable all features. + "", opt, reloc, - code_model, + CodeModel::Default, ) } From c422e0d13263aa11975e7a69b954e35ddd27cbc0 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Wed, 21 Jun 2023 17:46:54 +0200 Subject: [PATCH 16/21] build nightly macos aarch64 --- .github/workflows/nightly_macos_apple_silicon.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/nightly_macos_apple_silicon.yml b/.github/workflows/nightly_macos_apple_silicon.yml index 3c0e70fd237..d9d699885ee 100644 --- a/.github/workflows/nightly_macos_apple_silicon.yml +++ b/.github/workflows/nightly_macos_apple_silicon.yml @@ -1,4 +1,5 @@ on: + pull_request: workflow_dispatch: schedule: - cron: '0 9 * * *' From f0858faa5a5353d140e570f3ad902848e59e3238 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Wed, 21 Jun 2023 17:56:51 +0200 Subject: [PATCH 17/21] skip tests for now --- .github/workflows/nightly_macos_apple_silicon.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nightly_macos_apple_silicon.yml b/.github/workflows/nightly_macos_apple_silicon.yml index d9d699885ee..154e1a66503 100644 --- a/.github/workflows/nightly_macos_apple_silicon.yml +++ b/.github/workflows/nightly_macos_apple_silicon.yml @@ -18,8 +18,8 @@ jobs: - name: llvm version run: llc --version | grep LLVM - - name: run tests - run: cargo test --locked --release + #- name: run tests + # run: cargo test --locked --release - name: get commit SHA run: echo "SHA=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV From 6b96884c4c5d048cf902b0e02c0c3428b8102ca6 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Thu, 22 Jun 2023 21:08:39 +0200 Subject: [PATCH 18/21] undo temp changes --- .github/workflows/nightly_macos_apple_silicon.yml | 5 ++--- .github/workflows/nightly_macos_x86_64.yml | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/nightly_macos_apple_silicon.yml b/.github/workflows/nightly_macos_apple_silicon.yml index 154e1a66503..3c0e70fd237 100644 --- a/.github/workflows/nightly_macos_apple_silicon.yml +++ b/.github/workflows/nightly_macos_apple_silicon.yml @@ -1,5 +1,4 @@ on: - pull_request: workflow_dispatch: schedule: - cron: '0 9 * * *' @@ -18,8 +17,8 @@ jobs: - name: llvm version run: llc --version | grep LLVM - #- name: run tests - # run: cargo test --locked --release + - name: run tests + run: cargo test --locked --release - name: get commit SHA run: echo "SHA=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV diff --git a/.github/workflows/nightly_macos_x86_64.yml b/.github/workflows/nightly_macos_x86_64.yml index a7dd534e009..43e5ce868ff 100644 --- a/.github/workflows/nightly_macos_x86_64.yml +++ b/.github/workflows/nightly_macos_x86_64.yml @@ -1,5 +1,4 @@ on: - pull_request: workflow_dispatch: schedule: - cron: '0 9 * * *' # 9=9am utc+0 @@ -18,7 +17,7 @@ jobs: run: ./ci/write_version.sh - name: execute rust tests - run: cargo test --release --locked -- --skip opaque_wrap_function --skip gen_list::bool_list_literal --skip platform_switching_swift --skip swift_ui --skip gen_str::str_append_scalar --skip gen_tags::phantom_polymorphic_record --skip parse_letter_counts --skip hello_world + run: cargo test --release --locked -- --skip opaque_wrap_function --skip gen_list::bool_list_literal --skip platform_switching_swift --skip swift_ui --skip gen_str::str_append_scalar --skip gen_tags::phantom_polymorphic_record # swift tests are skipped because of "Could not find or use auto-linked library 'swiftCompatibilityConcurrency'" on macos-11 x86_64 CI machine # this issue may be caused by using older versions of XCode From 8c118f7bd0192a0bf850da1a8019b628250cfca2 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Thu, 22 Jun 2023 21:10:45 +0200 Subject: [PATCH 19/21] fmt --- crates/compiler/gen_llvm/src/llvm/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/compiler/gen_llvm/src/llvm/build.rs b/crates/compiler/gen_llvm/src/llvm/build.rs index bf0774e6ab5..265a5ba504d 100644 --- a/crates/compiler/gen_llvm/src/llvm/build.rs +++ b/crates/compiler/gen_llvm/src/llvm/build.rs @@ -51,7 +51,7 @@ use roc_std::RocDec; use roc_target::{PtrWidth, TargetInfo}; use std::convert::TryInto; use std::path::Path; -use target_lexicon::{Architecture, OperatingSystem, Triple, Aarch64Architecture}; +use target_lexicon::{Aarch64Architecture, Architecture, OperatingSystem, Triple}; use super::convert::{struct_type_from_union_layout, RocUnion}; use super::intrinsics::{ From aa4f092e360ec266c9e70402714b4eca0d2ee8b8 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Thu, 22 Jun 2023 22:33:10 +0200 Subject: [PATCH 20/21] use basic-cli 0.4 --- examples/helloWorld.roc | 2 +- examples/parser/examples/letter-counts.roc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/helloWorld.roc b/examples/helloWorld.roc index 76bd2fcfa73..6501e3f0d46 100644 --- a/examples/helloWorld.roc +++ b/examples/helloWorld.roc @@ -1,5 +1,5 @@ app "helloWorld" - packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br" } + packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br" } imports [pf.Stdout] provides [main] to pf diff --git a/examples/parser/examples/letter-counts.roc b/examples/parser/examples/letter-counts.roc index b2649ffb53a..0978188a117 100644 --- a/examples/parser/examples/letter-counts.roc +++ b/examples/parser/examples/letter-counts.roc @@ -1,6 +1,6 @@ app "example" packages { - cli: "https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br", + cli: "https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br", parser: "../package/main.roc", } imports [ From bdb93fda5ea7eaade2e5ccc130037e6439ccc500 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 22 Jun 2023 16:58:50 -0400 Subject: [PATCH 21/21] Update to basic-cli 0.4.0 --- .../newline_in_packages.full.formatted.roc | 2 +- .../pass/newline_in_packages.full.result-ast | 2 +- .../pass/newline_in_packages.full.roc | 2 +- www/generate_tutorial/src/input/tutorial.md | 38 +++++++++---------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.formatted.roc b/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.formatted.roc index dfc6082b37d..65594cfd384 100644 --- a/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.formatted.roc +++ b/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.formatted.roc @@ -1,7 +1,7 @@ app "hello" packages { pf: - "https://github.com/roc-lang/basic-cli/releases/download/0.1.3/5SXwdW7rH8QAOnD71IkHcFxCmBEPtFSLAIkclPEgjHQ.tar.br", + "https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br", } imports [pf.Stdout] provides [main] to pf diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.result-ast b/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.result-ast index 7a72869a703..54d44bb72aa 100644 --- a/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.result-ast +++ b/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.result-ast @@ -24,7 +24,7 @@ Full { Newline, ], package_name: @31-145 PackageName( - "https://github.com/roc-lang/basic-cli/releases/download/0.1.3/5SXwdW7rH8QAOnD71IkHcFxCmBEPtFSLAIkclPEgjHQ.tar.br", + "https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br", ), }, [ diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.roc b/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.roc index 29556d163ca..aebf7bf46a8 100644 --- a/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.roc +++ b/crates/compiler/test_syntax/tests/snapshots/pass/newline_in_packages.full.roc @@ -1,6 +1,6 @@ app "hello" packages { pf: -"https://github.com/roc-lang/basic-cli/releases/download/0.1.3/5SXwdW7rH8QAOnD71IkHcFxCmBEPtFSLAIkclPEgjHQ.tar.br" +"https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br" } imports [pf.Stdout] provides [main] to pf diff --git a/www/generate_tutorial/src/input/tutorial.md b/www/generate_tutorial/src/input/tutorial.md index 90e43fad064..2ee3c608aec 100644 --- a/www/generate_tutorial/src/input/tutorial.md +++ b/www/generate_tutorial/src/input/tutorial.md @@ -126,7 +126,7 @@ Make a file named `main.roc` and put this in it: ```roc app "hello" - packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br" } + packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br" } imports [pf.Stdout] provides [main] to pf @@ -427,11 +427,11 @@ Roc supports optional record fields using the `?` operator. This can be a useful In Roc you can write a function like: ```roc -table = \{ - height, - width, - title? "oak", - description? "a wooden table" +table = \{ + height, + width, + title? "oak", + description? "a wooden table" } -> ``` @@ -469,7 +469,7 @@ optional field, you'll get a compile error. This means it's never possible to end up with an *optional value* that exists outside a record field. Optionality is a concept that exists only in record fields, and it's intended for the use case of config records like this. The -ergonomics of destructuring mean this wouldn't be a good fit for data modeling, consider using a `Result` type instead. +ergonomics of destructuring mean this wouldn't be a good fit for data modeling, consider using a `Result` type instead. ## [Tags](#tags) {#tags} @@ -1114,10 +1114,10 @@ Here, Roc's compiler will infer that `color`'s type is `[Red, Yellow, Green]`, b A type can be defined to be opaque to hide its internal structure. This is a lot more amazing than it may seem. It can make your code more modular, robust, and easier to read: - If a type is opaque you can modify its internal structure and be certain that no dependencies need to be updated. -- You can prevent that data needs to be checked multiple times. For example, you can create an opaque `NonEmptyList` from a `List` after you've checked it. Now all functions that you pass this `NonEmptyList` to do not need to handle the empty list case. +- You can prevent that data needs to be checked multiple times. For example, you can create an opaque `NonEmptyList` from a `List` after you've checked it. Now all functions that you pass this `NonEmptyList` to do not need to handle the empty list case. - Having the type `Username` in a type signature gives you more context compared to `Str`. Even if the `Username` is an opaque type for `Str`. -You can create an opaque type with the `:=` operator. Let's make one called `Username`: +You can create an opaque type with the `:=` operator. Let's make one called `Username`: ```roc Username := Str @@ -1337,7 +1337,7 @@ So you'll want to use `roc dev` or `roc test` to get the output for `expect`. Each `.roc` file is a separate module and contains Roc code for different purposes. Here are all of the different types of modules that Roc supports; -- **Builtins** provide functions that are automatically imported into every module. +- **Builtins** provide functions that are automatically imported into every module. - **Applications** are combined with a platform and compiled into an executable. - **Interfaces** provide functions which can be imported into other modules. - **Packages** organise modules to share functionality across applications and platforms. @@ -1371,7 +1371,7 @@ Let's take a closer look at the part of `main.roc` above the `main` def: ```roc app "hello" - packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br" } + packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br" } imports [pf.Stdout] provides main to pf ``` @@ -1383,7 +1383,7 @@ The line `app "hello"` states that this module defines a Roc application, and th The remaining lines all involve the [platform](https://github.com/roc-lang/roc/wiki/Roc-concepts-explained#platform) this application is built on: ```roc -packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br" } +packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br" } imports [pf.Stdout] provides [main] to pf ``` @@ -1422,11 +1422,11 @@ See [Parser Package](https://github.com/roc-lang/roc/tree/main/examples/parser/p Package documentation can be generated using the Roc cli with `roc docs /package/*.roc`. -Build a package for distribution with `roc build --bundle .tar.br /package/main.roc`. This will create a single tarball that can then be easily shared online using a URL. +Build a package for distribution with `roc build --bundle .tar.br /package/main.roc`. This will create a single tarball that can then be easily shared online using a URL. You can import a package that is available either locally, or from a URL into a Roc application or platform. This is achieved by specifying the package in the `packages` section of the application or platform file structure. For example, `packages { .., parser: "" }` is an example that imports a parser module from a URL. -How does the Roc cli import and download a package from a URL? +How does the Roc cli import and download a package from a URL? 1. First it checks to see whether the relevant folder already exists in the local filesystem and if not, creates it. If there is a package already downloaded then there is no need to download or extract anything. Packages are cached in a directory, typically `~/.cache/roc` on UNIX, and `%APPDATA%\\Roc` on Windows. 2. It then downloads the file at that URL and verifies that the hash of the file matches the hash at the end of the URL. @@ -1438,7 +1438,7 @@ Including the hash solves a number of problems: 1. The package at the URL can not suddenly change and cause different behavior. 2. Because of 1. there is no need to check the URL on every compilation to see if we have the latest version. -3. If the domain of the URL expires, a malicious actor can change the package but the hash will not match so the roc cli will reject it. +3. If the domain of the URL expires, a malicious actor can change the package but the hash will not match so the roc cli will reject it. ### [Interface Modules](#interface-modules) {#interface-modules} @@ -1469,7 +1469,7 @@ Let's start with a basic "Hello World" program. ```roc app "cli-tutorial" - packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br" } + packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br" } imports [pf.Stdout] provides [main] to pf @@ -1499,7 +1499,7 @@ Let's change `main` to read a line from `stdin`, and then print it back out agai ```roc app "cli-tutorial" - packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br" } + packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br" } imports [pf.Stdout, pf.Stdin, pf.Task] provides [main] to pf @@ -1540,7 +1540,7 @@ This works, but we can make it a little nicer to read. Let's change it to the fo ```roc app "cli-tutorial" - packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br" } + packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br" } imports [pf.Stdout, pf.Stdin, pf.Task.{ await }] provides [main] to pf @@ -1960,7 +1960,7 @@ For this reason, any time you see a function that only runs a `when` on its only Here are various Roc expressions involving operators, and what they desugar to. | Expression | Desugars To | -| ----------------------------- | ------------------ | +| ----------------------------- | ------------------ | | `a + b` | `Num.add a b` | | `a - b` | `Num.sub a b` | | `a * b` | `Num.mul a b` |