From 40bd8ff1dea023aa1cb0045915c7cee011f23d31 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 20 Nov 2022 10:36:30 -0500 Subject: [PATCH] Support loading platform modules via HTTPS --- Cargo.lock | 1 + crates/compiler/load_internal/Cargo.toml | 1 + crates/compiler/load_internal/src/file.rs | 32 ++++++++++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5121fc5d9f..ae3e1fb917 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3940,6 +3940,7 @@ dependencies = [ "roc_late_solve", "roc_module", "roc_mono", + "roc_packaging", "roc_parse", "roc_problem", "roc_region", diff --git a/crates/compiler/load_internal/Cargo.toml b/crates/compiler/load_internal/Cargo.toml index 9c7d1ad290..aaea20998b 100644 --- a/crates/compiler/load_internal/Cargo.toml +++ b/crates/compiler/load_internal/Cargo.toml @@ -13,6 +13,7 @@ roc_region = { path = "../region" } roc_module = { path = "../module" } roc_types = { path = "../types" } roc_can = { path = "../can" } +roc_packaging = { path = "../../packaging" } roc_constrain = { path = "../constrain" } roc_derive_key = { path = "../derive_key" } roc_derive = { path = "../derive" } diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index dcbd754305..9ea14f48d6 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -37,6 +37,7 @@ use roc_mono::ir::{ use roc_mono::layout::{ CapturesNiche, LambdaName, Layout, LayoutCache, LayoutProblem, STLayoutInterner, }; +use roc_packaging::https::PackageMetadata; use roc_parse::ast::{self, Defs, ExtractSpaces, Spaced, StrLiteral, TypeAnnotation}; use roc_parse::header::{ExposedName, ImportsEntry, PackageEntry, PlatformHeader, To, TypedIdent}; use roc_parse::header::{HeaderFor, ModuleNameEnum, PackageName}; @@ -3121,8 +3122,13 @@ fn finish( } } -/// Load a `platform` module -fn load_platform_module<'a>( +enum PackageSrc<'a> { + Filesystem(&'a Path), + Url(PackageMetadata<'a>), +} + +/// Load a `platform` module from disk +fn load_platform_module_from_disk<'a>( arena: &'a Bump, filename: &Path, shorthand: &'a str, @@ -3132,7 +3138,7 @@ fn load_platform_module<'a>( ) -> Result, LoadingProblem<'a>> { let module_start_time = Instant::now(); let file_io_start = Instant::now(); - let file = fs::read(filename); + let file = fs::read(dbg!(filename)); let file_io_duration = file_io_start.elapsed(); match file { @@ -3605,17 +3611,29 @@ fn parse_header<'a>( shorthand, package_name: Loc { - value: package_name, + value: package_path, .. }, .. }) = opt_base_package { - // check whether we can find a `platform` module file - let platform_module_path = app_file_dir.join(package_name.to_str()); + let src = package_path.to_str(); + + // check whether we can find a `platform` module file on disk + let platform_module_path = if src.starts_with("https://") { + // If this is a HTTPS package, synchronously download it + // to the cache before proceeding. + + // TODO we should do this async; however, with the current + // architecture of fie.rs (which doesn't use async/await), + // this would be very difficult! + todo!() + } else { + app_file_dir.join(src) + }; if platform_module_path.as_path().exists() { - let load_platform_module_msg = load_platform_module( + let load_platform_module_msg = load_platform_module_from_disk( arena, &platform_module_path, shorthand,