Skip to content

Commit

Permalink
Merge branch 'main' of github.com:roc-lang/basic-cli into 0.13.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-4 committed Jul 27, 2024
2 parents 46751d2 + 15840fc commit 79045e0
Show file tree
Hide file tree
Showing 17 changed files with 467 additions and 143 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ jobs:
# Workaround for https://github.com/roc-lang/roc/issues/6688
- name: Check if crash occurred
run: grep -zqv "crashed" all_tests_output.log

- name: Install dependencies for musl build
run: |
sudo apt-get install -y musl-tools
rustup target add x86_64-unknown-linux-musl
- name: Test building with musl target
run: CARGO_BUILD_TARGET=x86_64-unknown-linux-musl ./roc_nightly/roc build.roc --prebuilt-platform -- --roc ./roc_nightly/roc

- name: Test using musl build
run: |
# no need to build platform anymore
sed -i '/build\.roc\|jump-start\.sh/d' ./ci/all_tests.sh
ROC=./roc_nightly/roc EXAMPLES_DIR=./examples/ ./ci/all_tests.sh
15 changes: 13 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ members = [
[profile.release]
lto = true
strip = "debuginfo"
codegen-units = 1
# Enabling this triggered a segmentation fault (see issue github.com/roc-lang/roc/issues/6121).
# That issue is notoriously fickle, so disableing this may just happen to shuffle the code enough to avoid it.
# Try re-enableing this again in the future after some code changes, it may no longer trigger this issue.
# Setting it to 1 should improve execution speed by making things easier to optimize for LLVM.
# codegen-units = 1
66 changes: 41 additions & 25 deletions build.roc
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,19 @@ run = \maybeRoc ->

generateGlue! rocCmd

# target is MacosArm64, LinuxX64,...
target = getNativeTarget!
osAndArch = getOSAndArch!

stubLibPath = "platform/libapp.$(stubFileExtension target)"
stubLibPath = "platform/libapp.$(stubFileExtension osAndArch)"

buildStubAppLib! rocCmd stubLibPath

cargoBuildHost!

copyHostLib! target
rustTargetFolder = getRustTargetFolder!

preprocessHost! rocCmd stubLibPath
copyHostLib! osAndArch rustTargetFolder

preprocessHost! rocCmd stubLibPath rustTargetFolder

info! "Successfully built platform files!"

Expand All @@ -73,14 +74,14 @@ generateGlue = \rocCmd ->
|> Cmd.exec ["glue", "glue.roc", "crates/", "platform/main.roc"]
|> Task.mapErr! ErrGeneratingGlue

getNativeTarget : Task RocTarget _
getNativeTarget =
info! "Getting the native target ..."
getOSAndArch : Task OSAndArch _
getOSAndArch =
info! "Getting the native operating system and architecture ..."

Env.platform
|> Task.await convertNativeTarget
|> Task.await convertOSAndArch

RocTarget : [
OSAndArch : [
MacosArm64,
MacosX64,
LinuxArm64,
Expand All @@ -89,8 +90,8 @@ RocTarget : [
WindowsX64,
]

convertNativeTarget : _ -> Task RocTarget _
convertNativeTarget =\{os, arch} ->
convertOSAndArch : _ -> Task OSAndArch _
convertOSAndArch =\{os, arch} ->
when (os, arch) is
(MACOS, AARCH64) -> Task.ok MacosArm64
(MACOS, X64) -> Task.ok MacosX64
Expand All @@ -105,23 +106,36 @@ buildStubAppLib = \rocCmd, stubLibPath ->
|> Cmd.exec ["build", "--lib", "platform/libapp.roc", "--output", stubLibPath, "--optimize"]
|> Task.mapErr! ErrBuildingAppStub

stubFileExtension : RocTarget -> Str
stubFileExtension = \target ->
when target is
stubFileExtension : OSAndArch -> Str
stubFileExtension = \osAndArch ->
when osAndArch is
MacosX64 | MacosArm64 -> "dylib"
LinuxArm64 | LinuxX64-> "so"
WindowsX64| WindowsArm64 -> "dll"

prebuiltStaticLibFile : RocTarget -> Str
prebuiltStaticLibFile = \target ->
when target is
prebuiltStaticLibFile : OSAndArch -> Str
prebuiltStaticLibFile = \osAndArch ->
when osAndArch is
MacosArm64 -> "macos-arm64.a"
MacosX64 -> "macos-x64.a"
LinuxArm64 -> "linux-arm64.a"
LinuxX64 -> "linux-x64.a"
WindowsArm64 -> "windows-arm64.lib"
WindowsX64 -> "windows-x64.lib"

getRustTargetFolder : Task Str _
getRustTargetFolder =
when Env.var "CARGO_BUILD_TARGET" |> Task.result! is
Ok targetEnvVar ->
if Str.isEmpty targetEnvVar then
Task.ok "target/release/"
else
Task.ok "target/$(targetEnvVar)/release/"
Err e ->
info! "Failed to get env var CARGO_BUILD_TARGET with error \(Inspect.toStr e). Assuming default CARGO_BUILD_TARGET (native)..."

Task.ok "target/release/"

cargoBuildHost : Task {} _
cargoBuildHost =
cargoBuildArgs =
Expand All @@ -133,20 +147,22 @@ cargoBuildHost =
|> Cmd.exec cargoBuildArgs
|> Task.mapErr! ErrBuildingHostBinaries

copyHostLib : RocTarget -> Task {} _
copyHostLib = \target ->
hostBuildPath = "target/release/libhost.a"
hostDestPath = "platform/$(prebuiltStaticLibFile target)"
copyHostLib : OSAndArch, Str -> Task {} _
copyHostLib = \osAndArch, rustTargetFolder ->
hostBuildPath =
"$(rustTargetFolder)libhost.a"

hostDestPath = "platform/$(prebuiltStaticLibFile osAndArch)"

info! "Moving the prebuilt binary from $(hostBuildPath) to $(hostDestPath) ..."
"cp"
|> Cmd.exec [hostBuildPath, hostDestPath]
|> Task.mapErr! ErrMovingPrebuiltLegacyBinary

preprocessHost : Str, Str -> Task {} _
preprocessHost = \rocCmd, stubLibPath ->
preprocessHost : Str, Str, Str -> Task {} _
preprocessHost = \rocCmd, stubLibPath, rustTargetFolder ->
info! "Preprocessing surgical host ..."
surgicalBuildPath = "target/release/host"
surgicalBuildPath = "$(rustTargetFolder)host"

rocCmd
|> Cmd.exec ["preprocess-host", surgicalBuildPath, "platform/main.roc", stubLibPath]
Expand Down
2 changes: 1 addition & 1 deletion ci/all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ find . -type d -name "roc_nightly" -prune -o -type f -name "*.roc" -print | whil

# don't exit script if test_command fails
set +e
test_command=$($ROC test "$file")
test_command=$($ROC test "$file" --prebuilt-platform)
test_exit_code=$?
set -e

Expand Down
6 changes: 5 additions & 1 deletion crates/roc_host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ license = "UPL-1.0"
edition = "2021"
description = "This provides the [host](https://github.com/roc-lang/roc/wiki/Roc-concepts-explained#host) implementation for the platform."

links = "app"

[lib]
name = "roc_host"
path = "src/lib.rs"

[dependencies]
roc_std = { path = "../roc_std" }
libc = "=0.2.150"
libc = "=0.2.155"
backtrace = "=0.3.69"
hyper = { version = "=0.14.27", default-features = false, features = ["http1", "client"] }
hyper-rustls = { version = "=0.24.2", default-features = false, features = ["http1", "tls12", "native-tokio"]}
tokio = { version = "=1.31.0", default-features = false}
crossterm = "=0.27.0"
memmap2 = "=0.9.4"
memchr = "=2.7.4"
File renamed without changes.
Loading

0 comments on commit 79045e0

Please sign in to comment.