Merge remote-tracking branch 'origin/trunk' into sized-functions-inference

This commit is contained in:
Folkert 2020-10-19 00:28:39 +02:00
commit e2496f22eb
7 changed files with 115 additions and 27 deletions

View File

@ -11,7 +11,7 @@ To build the compiler, you need these installed:
To run the test suite (via `cargo test`), you additionally need to install:
* [`valgrind`](https://www.valgrind.org/)
* [`valgrind`](https://www.valgrind.org/) (needs special treatment to [install on macOS](https://stackoverflow.com/a/61359781)]
Some systems may already have `libc++-dev` on them, but if not, you may need to install it. (On Ubuntu, this can be done with `sudo apt-get install libc++-dev`.) macOS systems
should already have `libunwind`, but other systems will need to install it
@ -28,6 +28,40 @@ For macOS, you can run `brew install llvm` (but before you do so, check the vers
There are also plenty of alternative options at http://releases.llvm.org/download.html
## Using Nix
### Install
Using [nix](https://nixos.org/download.html) is a quick way to get an environment bootstrapped with a single command.
Anyone having trouble installing the proper version of LLVM themselves might also prefer this method.
First, install nix:
`curl -L https://nixos.org/nix/install | sh`
If MacOS and using a version >= 10.15:
`sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume`
You may prefer to setup up the volume manually by following nix documentation.
> You my need to restart your terminal
### Usage
Now with nix installed you just need to run one command:
`nix-shell`
> This may not output anything for a little while. This is normal, hang in there. Also make sure you are in the roc project root.
You should be in a shell with everything needed to build already installed. Next run:
`cargo run repl`
You should be in a repl now. Have fun!
## Troubleshooting
Create an issue if you run into problems not listed here.

1
Cargo.lock generated
View File

@ -2321,6 +2321,7 @@ dependencies = [
"serde-xml-rs",
"strip-ansi-escapes",
"target-lexicon",
"tempfile",
"tokio",
]

View File

@ -88,3 +88,4 @@ quickcheck_macros = "0.8"
strip-ansi-escapes = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde-xml-rs = "0.4"
tempfile = "3.1.0"

View File

@ -11,7 +11,9 @@ mod helpers;
#[cfg(test)]
mod cli_run {
use crate::helpers::{example_file, extract_valgrind_errors, run_roc, run_with_valgrind, Out};
use crate::helpers::{
example_file, extract_valgrind_errors, run_cmd, run_roc, run_with_valgrind, Out,
};
#[test]
fn run_hello_world() {
@ -21,9 +23,9 @@ mod cli_run {
}
assert!(out.status.success());
let valgrind_out =
let (valgrind_out, raw_xml) =
run_with_valgrind(&[example_file("hello-world", "app").to_str().unwrap()]);
assert!(valgrind_out.status.success());
let ending = "Hello, World!!!!!!!!!!!!!\n";
if !&valgrind_out.stdout.ends_with(ending) {
panic!(
@ -31,10 +33,11 @@ mod cli_run {
ending, &valgrind_out.stdout
);
}
let memory_errors = extract_valgrind_errors(&valgrind_out.stderr);
let memory_errors = extract_valgrind_errors(&raw_xml);
if !memory_errors.is_empty() {
panic!("{:?}", memory_errors);
}
assert!(valgrind_out.status.success());
}
check_hello_world_output(run_roc(&[
"build",
@ -55,9 +58,9 @@ mod cli_run {
}
assert!(out.status.success());
let valgrind_out =
run_with_valgrind(&[example_file("quicksort", "app").to_str().unwrap()]);
assert!(valgrind_out.status.success());
// let (valgrind_out, raw_xml) =
// run_with_valgrind(&[example_file("quicksort", "app").to_str().unwrap()]);
let valgrind_out = run_cmd(example_file("quicksort", "app").to_str().unwrap(), &[]);
let ending = "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n";
if !&valgrind_out.stdout.ends_with(ending) {
panic!(
@ -65,10 +68,11 @@ mod cli_run {
ending, &valgrind_out.stdout
);
}
let memory_errors = extract_valgrind_errors(&valgrind_out.stderr);
if !memory_errors.is_empty() {
panic!("{:?}", memory_errors);
}
// let memory_errors = extract_valgrind_errors(&raw_xml);
// if !memory_errors.is_empty() {
// panic!("{:?}", memory_errors);
// }
assert!(valgrind_out.status.success());
}
// TODO: Uncomment this once we are correctly freeing the RocList even when in dev build.
@ -93,9 +97,9 @@ mod cli_run {
}
assert!(out.status.success());
let valgrind_out =
run_with_valgrind(&[example_file("multi-module", "app").to_str().unwrap()]);
assert!(valgrind_out.status.success());
// let (valgrind_out, raw_xml) =
// run_with_valgrind(&[example_file("multi-module", "app").to_str().unwrap()]);
let valgrind_out = run_cmd(example_file("multi-module", "app").to_str().unwrap(), &[]);
let ending = "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n";
if !&valgrind_out.stdout.ends_with(ending) {
panic!(
@ -103,10 +107,11 @@ mod cli_run {
ending, &valgrind_out.stdout
);
}
let memory_errors = extract_valgrind_errors(&valgrind_out.stderr);
if !memory_errors.is_empty() {
panic!("{:?}", memory_errors);
}
// let memory_errors = extract_valgrind_errors(&raw_xml);
// if !memory_errors.is_empty() {
// panic!("{:?}", memory_errors);
// }
assert!(valgrind_out.status.success());
}
// TODO: Uncomment this once we are correctly freeing the RocList even when in dev build.

View File

@ -3,14 +3,17 @@ extern crate inlinable_string;
extern crate roc_collections;
extern crate roc_load;
extern crate roc_module;
extern crate tempfile;
use roc_cli::repl::{INSTRUCTIONS, PROMPT, WELCOME_MESSAGE};
use serde::Deserialize;
use serde_xml_rs::from_str;
use std::env;
use std::io::Read;
use std::io::Write;
use std::path::PathBuf;
use std::process::{Command, ExitStatus, Stdio};
use tempfile::NamedTempFile;
pub struct Out {
pub stdout: String,
@ -57,13 +60,36 @@ pub fn run_roc(args: &[&str]) -> Out {
}
#[allow(dead_code)]
pub fn run_with_valgrind(args: &[&str]) -> Out {
pub fn run_cmd(cmd_name: &str, args: &[&str]) -> Out {
let mut cmd = Command::new(cmd_name);
for arg in args {
cmd.arg(arg);
}
let output = cmd
.output()
.expect(&format!("failed to execute cmd `{}` in CLI test", cmd_name));
Out {
stdout: String::from_utf8(output.stdout).unwrap(),
stderr: String::from_utf8(output.stderr).unwrap(),
status: output.status,
}
}
#[allow(dead_code)]
pub fn run_with_valgrind(args: &[&str]) -> (Out, String) {
//TODO: figure out if there is a better way to get the valgrind executable.
let mut cmd = Command::new("valgrind");
let named_tempfile =
NamedTempFile::new().expect("Unable to create tempfile for valgrind results");
let filepath = named_tempfile.path().to_str().unwrap();
cmd.arg("--tool=memcheck");
cmd.arg("--xml=yes");
cmd.arg("--xml-fd=2");
cmd.arg(format!("--xml-file={}", filepath));
for arg in args {
cmd.arg(arg);
}
@ -72,11 +98,19 @@ pub fn run_with_valgrind(args: &[&str]) -> Out {
.output()
.expect("failed to execute compiled `valgrind` binary in CLI test");
Out {
stdout: String::from_utf8(output.stdout).unwrap(),
stderr: String::from_utf8(output.stderr).unwrap(),
status: output.status,
}
let mut file = named_tempfile.into_file();
let mut raw_xml = String::new();
file.read_to_string(&mut raw_xml).unwrap();
(
Out {
stdout: String::from_utf8(output.stdout).unwrap(),
stderr: String::from_utf8(output.stderr).unwrap(),
status: output.status,
},
raw_xml,
)
}
#[derive(Debug, Deserialize)]
@ -125,7 +159,8 @@ pub struct ValgrindErrorXWhat {
#[allow(dead_code)]
pub fn extract_valgrind_errors(xml: &str) -> Vec<ValgrindError> {
let parsed_xml: ValgrindOutput =
from_str(xml).expect("failed to parse the `valgrind` xml output");
from_str(xml).unwrap_or_else(|err|
panic!("failed to parse the `valgrind` xml output. Error was:\n\n{:?}\n\nRaw valgrind output was:\n\n{}", err, xml));
parsed_xml
.fields
.iter()

11
editor/README.md Normal file
View File

@ -0,0 +1,11 @@
## Getting started
Run the following from the roc folder:
```
cargo run edit
```
## Troubleshooting
If you encounter an error like `gfx_backend_vulkan ... Failed to detect any valid GPUs in the current config ...` make sure the correct graphics card drivers are installed. On ubuntu `sudo ubuntu-drivers autoinstall` can resolve the problem.

1
examples/.gitignore vendored
View File

@ -1,3 +1,4 @@
app
host.o
c_host.o
app.dSYM