Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ target
generated-docs
generated-docs-*
.direnv
.envrc
*.rs.bk
*.o
*.so
Expand Down
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,35 @@ For local work, use any recent `roc` on `PATH`, or download the latest archive
for your operating system from the
[`roc-lang/nightlies` releases](https://github.com/roc-lang/nightlies/releases/latest).

## Nix Development Environment

With Nix's `nix-command` and `flakes` features enabled, the flake provides Roc
nightly, the Rust toolchain and cross-compilation standard libraries, Zig,
Python, and the documentation preview server on supported Linux and macOS
systems. Enter it with:

```sh
nix develop
```

To load the shell automatically, install [`direnv`](https://direnv.net/) and
hook it into your shell. The checked-in `.envrc` uses direnv's `use flake`;
install [`nix-direnv`](https://github.com/nix-community/nix-direnv) as well if
your direnv version does not provide it. Then simply approve `.envrc` once:

```sh
direnv allow
```

The lock file pins every flake input, including the Roc nightly supplied by
[`roc-overlay`](https://github.com/thebrandonlucas/roc-overlay). CI deliberately
tracks the current nightly, while local updates are explicit. Update the pinned
compiler with:

```sh
nix flake update roc-overlay
```

## Code of Conduct

We are committed to providing a friendly, safe, and welcoming environment for all. See the [Code of Conduct](https://github.com/roc-lang/roc/blob/main/CODE_OF_CONDUCT.md) for details.
Expand Down
89 changes: 89 additions & 0 deletions flake.lock

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

78 changes: 78 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
description = "basic-cli development environment";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# nixos-unstable no longer supports Intel macOS.
nixpkgs-x86-darwin.url = "github:NixOS/nixpkgs/nixpkgs-26.05-darwin";
roc-overlay = {
url = "github:thebrandonlucas/roc-overlay";
inputs.nixpkgs.follows = "nixpkgs";
inputs.nixpkgs-darwin.follows = "nixpkgs-x86-darwin";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
{
nixpkgs,
nixpkgs-x86-darwin,
roc-overlay,
rust-overlay,
...
}:
let
inherit (nixpkgs) lib;

supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = lib.genAttrs supportedSystems;
rustToolchainConfig = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain;
rustTargets = [
"x86_64-apple-darwin"
"aarch64-apple-darwin"
"x86_64-unknown-linux-musl"
"aarch64-unknown-linux-musl"
];
pkgsFor =
system:
import (if system == "x86_64-darwin" then nixpkgs-x86-darwin else nixpkgs) {
inherit system;
overlays = [
roc-overlay.overlays.default
rust-overlay.overlays.default
];
};
in
{
formatter = forAllSystems (system: (pkgsFor system).nixfmt);

devShells = forAllSystems (
system:
let
pkgs = pkgsFor system;
rustToolchain = pkgs.rust-bin.fromRustupToolchain (
rustToolchainConfig // { targets = rustTargets; }
);
in
{
default = pkgs.mkShell {
packages = [
pkgs.rocpkgs.nightly
pkgs.python3
rustToolchain
pkgs.simple-http-server
pkgs.zig_0_16
];
};
}
);
};
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
# b) update `channel = "nightly-OLD_DATE"` below

channel = "1.83.0" # check ^^^ when changing this
components = ["rust-analyzer"]
components = ["rust-analyzer", "llvm-tools-preview"]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support host stripping performed in scripts/build.py

#
# channel = "nightly-2024-04-28" # 1.79.0 nightly to be able to use unstable features
24 changes: 24 additions & 0 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,31 @@ def musl_build_env(rust_target: str) -> dict[str, str]:
return env


def rust_target_is_installed(rust_target: str) -> bool:
result = subprocess.run(
["rustc", "--print", "target-libdir", "--target", rust_target],
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
text=True,
)
return result.returncode == 0 and Path(result.stdout.strip()).is_dir()


def install_rust_target(rust_target: str, *, required: bool = False) -> None:
if rust_target_is_installed(rust_target):
return

if shutil.which("rustup") is None:
message = (
f"Rust target {rust_target} is not installed and rustup is unavailable; "
"enter `nix develop` or install the target manually"
)
if required:
raise SystemExit(message)
print(f"warning: {message}")
return

run("rustup", "target", "add", rust_target, check=required)
Comment on lines +120 to 145

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we assumed Rust targets were always managed bu rustup and unconditionally ran this every time, even if the target was already installed. Nix manages this via the nix store and does not use this rustup. So this would fail with rustup: command not found even if all the targets were available. By using rustc to ask where the target libraries should be, then verifying it exists there via result.returncode == 0 and Path(result.stdout.strip()).is_dir(), we maintain backward compat for non-nix users.



Expand Down
Loading