From 6483cff431ca54a44ee8708a654a51be36bc0803 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 30 Apr 2021 23:02:16 +0200 Subject: [PATCH 01/14] Work on Mango wrapper script --- cli/resource/init/mango.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 cli/resource/init/mango.sh diff --git a/cli/resource/init/mango.sh b/cli/resource/init/mango.sh new file mode 100644 index 0000000..44d03d7 --- /dev/null +++ b/cli/resource/init/mango.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env sh + +# Wrapper that runs Mango using Docker. Arguments are passed on to Mango CLI. +# A continuously-running daemon container is started, if it is not running. + +if [ -z "$PROJECT_NAME" ]; +then + PROJECT_NAME="$(basename "$(pwd)")" +fi + +if [ -z "$MANGO_DOCKER_IMAGE" ]; +then + MANGO_DOCKER_IMAGE="mangocode/mango:latest" +fi + + +if ! command -v docker 1> /dev/null 2> /dev/null +then + echo "Docker must be installed to run Mango" + exit 1 +fi + +docker run \ + --name "mangod-$PROJECT_NAME" \ + --rm \ + --entrypoint /mangod \ + "$MANGO_DOCKER_IMAGE" From 528efdb09d20e5b06f5900634f478db0944872f0 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 30 Apr 2021 23:21:04 +0200 Subject: [PATCH 02/14] Check image age to see if it needs updating --- cli/resource/init/mango.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cli/resource/init/mango.sh b/cli/resource/init/mango.sh index 44d03d7..28b16c4 100644 --- a/cli/resource/init/mango.sh +++ b/cli/resource/init/mango.sh @@ -3,6 +3,8 @@ # Wrapper that runs Mango using Docker. Arguments are passed on to Mango CLI. # A continuously-running daemon container is started, if it is not running. +# Configuration is done through environment variables + if [ -z "$PROJECT_NAME" ]; then PROJECT_NAME="$(basename "$(pwd)")" @@ -13,6 +15,10 @@ then MANGO_DOCKER_IMAGE="mangocode/mango:latest" fi +#TODO @mark: cache dir etc, from Mango itself during init? but that'd make the wrapper platform-dependent + + +# Docker & image if ! command -v docker 1> /dev/null 2> /dev/null then @@ -20,6 +26,25 @@ then exit 1 fi +img_date="$(docker inspect -f '{{ .Created }}' "$MANGO_DOCKER_IMAGE" 2> /dev/null)" +if [ $? -ne 0 ] || [ -z "$img_date" ] +then + printf 'pulling docker image %s\n' "$MANGO_DOCKER_IMAGE" + docker pull "$MANGO_DOCKER_IMAGE" +fi +img_ts="$(date +%s -d $img_date)" +age_s="$(expr "$(date +%s)" - "$img_ts")" +echo "age is $age_s s" +if [ $age_s -gt 43200 ] +then + printf 'updating docker image %s\n' "$MANGO_DOCKER_IMAGE" + docker pull "$MANGO_DOCKER_IMAGE" +fi + +# Mango daemon + +set -eu + docker run \ --name "mangod-$PROJECT_NAME" \ --rm \ From 1d806f8cb0ee04e74453f87596eea43b6ad9c67f Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 1 May 2021 12:12:48 +0200 Subject: [PATCH 03/14] Get rid of over-fancy image update magic --- cli/resource/init/mango.sh | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/cli/resource/init/mango.sh b/cli/resource/init/mango.sh index 28b16c4..0964cf4 100644 --- a/cli/resource/init/mango.sh +++ b/cli/resource/init/mango.sh @@ -26,27 +26,15 @@ then exit 1 fi -img_date="$(docker inspect -f '{{ .Created }}' "$MANGO_DOCKER_IMAGE" 2> /dev/null)" -if [ $? -ne 0 ] || [ -z "$img_date" ] -then - printf 'pulling docker image %s\n' "$MANGO_DOCKER_IMAGE" - docker pull "$MANGO_DOCKER_IMAGE" -fi -img_ts="$(date +%s -d $img_date)" -age_s="$(expr "$(date +%s)" - "$img_ts")" -echo "age is $age_s s" -if [ $age_s -gt 43200 ] -then - printf 'updating docker image %s\n' "$MANGO_DOCKER_IMAGE" - docker pull "$MANGO_DOCKER_IMAGE" -fi - # Mango daemon set -eu +#TODO @mark: port might collide with other projects docker run \ --name "mangod-$PROJECT_NAME" \ --rm \ --entrypoint /mangod \ - "$MANGO_DOCKER_IMAGE" + -p 47558:47558 \ + "$MANGO_DOCKER_IMAGE" \ + --hostname 127.0.0.1 --port 47558 From ad9c0e39ad99cfe3a0346cbf8c3b9c8086c7cc61 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 2 May 2021 22:04:19 +0200 Subject: [PATCH 04/14] Switch to using base CI image --- Cargo.toml | 2 +- ci/simple.Dockerfile | 24 +++--------------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3f7ccd9..27bf9bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ name = "mango" path = "src/main.rs" [dependencies] -serde = { version = "1.0.125", features = ["derive"] } +serde = { version = "1.0.126", features = ["derive"] } bincode = "1.3.3" serde_json = "1.0.64" dirs = "3.0.2" diff --git a/ci/simple.Dockerfile b/ci/simple.Dockerfile index dc410c1..ce83508 100644 --- a/ci/simple.Dockerfile +++ b/ci/simple.Dockerfile @@ -1,24 +1,6 @@ -FROM clux/muslrust:nightly-2021-04-24 AS build - -ENV RUST_BACKTRACE=1 - -RUN rustup component add rustfmt -RUN rustup component add clippy -RUN cargo install cargo-outdated -RUN cargo install cargo-audit -RUN cargo install cargo-deny -RUN cargo install cargo-tree - -# Add the files needed to compile dependencies. -COPY ./Cargo.toml Cargo.lock ./ -RUN mkdir -p src && \ - printf '\nfn main() {\n\tprintln!("something went wrong while building the docker image")\n}\n' | tee src/main.rs - -# Build the dependencies, remove Cargo files so they have to be re-added. -RUN cargo build --tests &&\ - cargo build --release &&\ - rm -rf Cargo.toml Cargo.lock src/ +#TODO @mark: why compile still takes >1 min each despite pre-compiled dependencies? +FROM mangocode/mango_daily_base:2021-05-02 AS build # Copy the actual code. COPY ./Cargo.toml ./Cargo.lock ./deny.toml ./rustfmt.toml ./ @@ -27,7 +9,7 @@ COPY ./src/ ./src # Build (for test) RUN find . -name target -prune -o -type f &&\ touch -c src/main.rs &&\ - cargo --offline build --tests + cargo build --tests #TODO @mark: move up^ ENV RUST_LOG='debug,ws=warn,mio=warn' From e32586a2c3914c34277ab860b5f6f65da92c26bf Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 12 May 2021 22:54:56 +0200 Subject: [PATCH 05/14] Disable a test and move resource directory --- {cli/resource => resource}/init/mango.sh | 0 src/cli/e2e.rs | 18 +++++++----------- 2 files changed, 7 insertions(+), 11 deletions(-) rename {cli/resource => resource}/init/mango.sh (100%) diff --git a/cli/resource/init/mango.sh b/resource/init/mango.sh similarity index 100% rename from cli/resource/init/mango.sh rename to resource/init/mango.sh diff --git a/src/cli/e2e.rs b/src/cli/e2e.rs index b160b5d..91e4719 100644 --- a/src/cli/e2e.rs +++ b/src/cli/e2e.rs @@ -77,7 +77,6 @@ fn run_with_daemon(args: &[&str], test: impl FnOnce(i32, &str, &str)) { .unwrap() .as_ref() .map(|exe_pth| { - eprintln!("HELLO A"); //TODO @mark: TEMPORARY! REMOVE THIS! let mut child = Command::new(&exe_pth) .arg("run-as-daemon") .arg("-p") @@ -85,13 +84,10 @@ fn run_with_daemon(args: &[&str], test: impl FnOnce(i32, &str, &str)) { .env("RUST_LOG", "debug,ws=warn,mio=warn") .spawn() .unwrap(); - eprintln!("HELLO B"); //TODO @mark: TEMPORARY! REMOVE THIS! let (_, out, _) = run_cli(&["daemon", "get", "status"]); - eprintln!("HELLO C"); //TODO @mark: TEMPORARY! REMOVE THIS! debug!("started mango daemon, status: {}", out); let (status, out, err) = run_cli_with(&exe_pth, args); test(status, &out, &err); - eprintln!("HELLO D"); //TODO @mark: TEMPORARY! REMOVE THIS! debug!("going to stop mango daemon"); sleep(Duration::from_millis(200)); //TODO @mark: TEMPORARY! REMOVE THIS! let (code, _, err) = run_cli(&["daemon", "stop"]); @@ -113,13 +109,13 @@ fn show_help() { //TODO @mark: - failing to start second daemon should fail test //TODO @mark: - it should not start a daemon because one is running //#[test] //TODO @mark: disabled -// fn compile_ir() { -// run_with_daemon(&["compile"], |status, out, err| { -// assert!(status == 0); -// println!("out: {}\n/out", out); //TODO @mark: TEMPORARY! REMOVE THIS! -// println!("err: {}\n/err", err); //TODO @mark: TEMPORARY! REMOVE THIS! -// }); -// } +//fn compile_ir() { +// run_with_daemon(&["compile"], |status, out, err| { +// assert!(status == 0); +// println!("out: {}\n/out", out); //TODO @mark: TEMPORARY! REMOVE THIS! +// println!("err: {}\n/err", err); //TODO @mark: TEMPORARY! REMOVE THIS! +// }); +//} #[test] fn daemon_start_stop() { From 97ca02d3cd0dd10637c010ff923a49a273e6750d Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 12 May 2021 23:24:44 +0200 Subject: [PATCH 06/14] Update the mango.sh script --- resource/init/mango.sh | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/resource/init/mango.sh b/resource/init/mango.sh index 0964cf4..46217d1 100644 --- a/resource/init/mango.sh +++ b/resource/init/mango.sh @@ -4,6 +4,8 @@ # A continuously-running daemon container is started, if it is not running. # Configuration is done through environment variables +# - PROJECT_NAME: name of the project (no whitespace) +# - MANGO_DOCKER_IMAGE: docker image including tag to use if [ -z "$PROJECT_NAME" ]; then @@ -15,26 +17,39 @@ then MANGO_DOCKER_IMAGE="mangocode/mango:latest" fi -#TODO @mark: cache dir etc, from Mango itself during init? but that'd make the wrapper platform-dependent +# Checks - -# Docker & image +set -eu if ! command -v docker 1> /dev/null 2> /dev/null then - echo "Docker must be installed to run Mango" + printf "Docker must be installed to run Mango\n" 1>&2 exit 1 fi +#TODO @mark: check that this is the root dir of the Mango project + # Mango daemon -set -eu +if [ -z "$(docker ps -q -f name=mangod)" ] +then + printf "Starting mango daemon container (mangod)\n" + docker run \ + --name "mangod" \ + --label started-by="$PROJECT_NAME" \ + -d --rm \ + -p 47558:47558 \ + "$MANGO_DOCKER_IMAGE" \ + -- run-as-daemon \ + --hostname 127.0.0.1 --port 47558 +fi + +# Mango cli -#TODO @mark: port might collide with other projects docker run \ - --name "mangod-$PROJECT_NAME" \ - --rm \ - --entrypoint /mangod \ - -p 47558:47558 \ + --name "mango-$PROJECT_NAME" \ + -it --rm \ + --mount type=bind,source="$(pwd)",target=/code \ "$MANGO_DOCKER_IMAGE" \ - --hostname 127.0.0.1 --port 47558 + -- "$@" + From 9d07615da74755edb381f76b66cc5aaee5431c3c Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 12 May 2021 23:28:59 +0200 Subject: [PATCH 07/14] Decrease logging verbosity and create docker network --- ci/simple.Dockerfile | 3 ++- resource/init/mango.sh | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ci/simple.Dockerfile b/ci/simple.Dockerfile index ce83508..e41d266 100644 --- a/ci/simple.Dockerfile +++ b/ci/simple.Dockerfile @@ -47,7 +47,8 @@ FROM scratch AS executable ENV PATH=/ ENV RUST_BACKTRACE=1 -ENV RUST_LOG='debug,ws=warn,mio=warn' +#ENV RUST_LOG='debug,ws=warn,mio=warn' +ENV RUST_LOG='warn' ENV MANGO_USER_CACHE_PATH='/cache' ENV MANGO_USER_CONFIG_PATH='/conf' WORKDIR /code diff --git a/resource/init/mango.sh b/resource/init/mango.sh index 46217d1..29f42e1 100644 --- a/resource/init/mango.sh +++ b/resource/init/mango.sh @@ -29,6 +29,11 @@ fi #TODO @mark: check that this is the root dir of the Mango project +# Docker network + +docker network inspect 'mangod-network' >/dev/null 2>/dev/null || \ + docker network create --driver bridge 'mangod-network' + # Mango daemon if [ -z "$(docker ps -q -f name=mangod)" ] @@ -38,9 +43,10 @@ then --name "mangod" \ --label started-by="$PROJECT_NAME" \ -d --rm \ + --network 'mangod-network' \ -p 47558:47558 \ "$MANGO_DOCKER_IMAGE" \ - -- run-as-daemon \ + run-as-daemon \ --hostname 127.0.0.1 --port 47558 fi @@ -49,7 +55,8 @@ fi docker run \ --name "mango-$PROJECT_NAME" \ -it --rm \ + --network 'mangod-network' \ --mount type=bind,source="$(pwd)",target=/code \ "$MANGO_DOCKER_IMAGE" \ - -- "$@" + "$@" From 3d8c77a3c14aa60a31974298067d44e54992b352 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 13 May 2021 22:23:59 +0200 Subject: [PATCH 08/14] Include main source file with some speculative syntax --- resource/init/main.mns | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 resource/init/main.mns diff --git a/resource/init/main.mns b/resource/init/main.mns new file mode 100644 index 0000000..17a3dd7 --- /dev/null +++ b/resource/init/main.mns @@ -0,0 +1,10 @@ + +use sys.print + +main: + # add your own code here! + print('hello world!') + +test "make sure tests are run": + assert 1 + 1 == 2 + From 3468fda190b14bdf54db7a5a587b6e4c323587d1 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 13 May 2021 22:30:59 +0200 Subject: [PATCH 09/14] Include mod file with extremely speculative structure --- resource/init/mod.mon | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 resource/init/mod.mon diff --git a/resource/init/mod.mon b/resource/init/mod.mon new file mode 100644 index 0000000..995171d --- /dev/null +++ b/resource/init/mod.mon @@ -0,0 +1,14 @@ + +package: + name = "$PROJECT_NAME$" + version = "0.1.0" + +targets: + $PROJECT_NAME$: + type: "executable" + path: "main.mns" + +dependencies: + test_dependency: "1.0.0" + + From 2246ff0b63fda958386e6d41005900ee7ffa167b Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 15 May 2021 19:17:06 +0200 Subject: [PATCH 10/14] Define argument for initializing project --- src/cli/init/mod.rs | 5 +++++ src/cli/mod.rs | 1 + src/cli/options/init.rs | 12 ++++++++++++ src/cli/options/mod.rs | 11 ++++------- src/main.rs | 8 +++++--- 5 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 src/cli/init/mod.rs create mode 100644 src/cli/options/init.rs diff --git a/src/cli/init/mod.rs b/src/cli/init/mod.rs new file mode 100644 index 0000000..3ab9990 --- /dev/null +++ b/src/cli/init/mod.rs @@ -0,0 +1,5 @@ +use crate::cli::options::init::InitCmd; + +pub fn handle_init_cmd(args: &InitCmd) -> Result<(), String> { + unimplemented!(); //TODO @mark: TEMPORARY! REMOVE THIS! +} diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 37a7f0f..bc26c68 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,3 +1,4 @@ +pub mod init; pub mod compile; pub mod options; pub mod source; diff --git a/src/cli/options/init.rs b/src/cli/options/init.rs new file mode 100644 index 0000000..5999677 --- /dev/null +++ b/src/cli/options/init.rs @@ -0,0 +1,12 @@ +use ::structopt::StructOpt; + +#[derive(StructOpt, Debug)] +pub struct InitCmd { + #[structopt( + short = "n", + long = "name", + help = "Name of the project to initialize. Defaults to directory name." + )] + pub name: Option, + +} diff --git a/src/cli/options/mod.rs b/src/cli/options/mod.rs index 17d511b..f57cf83 100644 --- a/src/cli/options/mod.rs +++ b/src/cli/options/mod.rs @@ -2,6 +2,7 @@ use ::structopt::StructOpt; use crate::common::util::MangodArgs; +pub mod init; pub mod clean; pub mod compile; pub mod daemon; @@ -34,19 +35,15 @@ pub struct MangoArgs { )] pub quiet: bool, - #[structopt( - long = "daemon", - help = "Only show the most important output.", - hidden_short_help=true - )] - pub daemon: bool, - #[structopt(subcommand)] pub cmd: MangoCommand, } #[derive(StructOpt, Debug)] pub enum MangoCommand { + #[structopt(about = "Initialize the current directory as a Mango project")] + Init(init::InitCmd), + // Note: this particular about text is part of a Github Action to check the CLI #[structopt(about = "Compile the code in the current directory to one of various formats")] Compile(compile::CompileCmd), diff --git a/src/main.rs b/src/main.rs index 814b7a9..a724fbd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,20 +7,21 @@ // #[allow(unused_imports)] // use ::mangolib; -#[global_allocator] -static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; - use ::std::process::exit; use ::env_logger; use crate::cli::compile::handle_compile_cmd; +use crate::cli::init::handle_init_cmd; use crate::cli::options::MangoArgs; use crate::cli::options::MangoCommand; use crate::cli::status::handle_daemon_cmd; use crate::common::util::MangodStatus; use crate::daemon::run_mango_daemon; +#[global_allocator] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; + mod cli; mod common; mod daemon; @@ -45,6 +46,7 @@ pub fn cli(args: MangoArgs) -> Result<(), String> { // }; let status = MangodStatus::determine(); match args.cmd { + MangoCommand::Init(init) => handle_init_cmd(&init), MangoCommand::Compile(compile) => handle_compile_cmd(&compile, &status), //TODO @mark: // match compile.target { From 3715c73ac69b72a379b5dddcbf7b28f8f4cebf0e Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 15 May 2021 19:36:28 +0200 Subject: [PATCH 11/14] Include all of the resource dir in the binary --- Cargo.lock | 43 +++++++++++++++++++++++++++ Cargo.toml | 1 + {resource => resources}/init/main.mns | 0 {resource => resources}/init/mango.sh | 0 {resource => resources}/init/mod.mon | 0 src/cli/init/mod.rs | 5 +++- src/main.rs | 3 ++ 7 files changed, 51 insertions(+), 1 deletion(-) rename {resource => resources}/init/main.mns (100%) rename {resource => resources}/init/mango.sh (100%) rename {resource => resources}/init/mod.mon (100%) diff --git a/Cargo.lock b/Cargo.lock index fcd52ad..17f13ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "anyhow" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" + [[package]] name = "async-channel" version = "1.6.1" @@ -464,6 +470,12 @@ dependencies = [ "wasi 0.10.2+wasi-snapshot-preview1", ] +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + [[package]] name = "gloo-timers" version = "0.2.1" @@ -518,6 +530,30 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "include_dir" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d58bdeb22b1c4691106c084b1063781904c35d0f22eda2a283598968eac61a" +dependencies = [ + "glob", + "include_dir_impl", + "proc-macro-hack", +] + +[[package]] +name = "include_dir_impl" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327869970574819d24d1dca25c891856144d29159ab797fa9dc725c5c3f57215" +dependencies = [ + "anyhow", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "instant" version = "0.1.9" @@ -636,6 +672,7 @@ dependencies = [ "bincode", "dirs", "env_logger", + "include_dir", "jemallocator", "lazy_static", "log", @@ -856,6 +893,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + [[package]] name = "proc-macro2" version = "1.0.26" diff --git a/Cargo.toml b/Cargo.toml index 27bf9bd..aca959a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ log = "0.4.14" async-std = "1.9.0" env_logger = "0.8.3" paw = "1.0.0" +include_dir = "0.6.0" [dev-dependencies] serial_test = "0.5.1" diff --git a/resource/init/main.mns b/resources/init/main.mns similarity index 100% rename from resource/init/main.mns rename to resources/init/main.mns diff --git a/resource/init/mango.sh b/resources/init/mango.sh similarity index 100% rename from resource/init/mango.sh rename to resources/init/mango.sh diff --git a/resource/init/mod.mon b/resources/init/mod.mon similarity index 100% rename from resource/init/mod.mon rename to resources/init/mod.mon diff --git a/src/cli/init/mod.rs b/src/cli/init/mod.rs index 3ab9990..3dba504 100644 --- a/src/cli/init/mod.rs +++ b/src/cli/init/mod.rs @@ -1,5 +1,8 @@ use crate::cli::options::init::InitCmd; pub fn handle_init_cmd(args: &InitCmd) -> Result<(), String> { - unimplemented!(); //TODO @mark: TEMPORARY! REMOVE THIS! + let name = args.name.unwrap_or_else(|| "dirname".to_owned()); + + + unimplemented!() } diff --git a/src/main.rs b/src/main.rs index a724fbd..bebb03d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use ::std::process::exit; use ::env_logger; +use ::include_dir::{Dir, include_dir}; use crate::cli::compile::handle_compile_cmd; use crate::cli::init::handle_init_cmd; @@ -26,6 +27,8 @@ mod cli; mod common; mod daemon; +pub(crate) const RESOURCES: Dir = include_dir!("resources"); + #[paw::main] fn main(args: MangoArgs) { env_logger::init(); From 38d64570cfae860bc5c8d0a941d2d713e4a99b50 Mon Sep 17 00:00:00 2001 From: Mark Verleg Date: Wed, 7 Jul 2021 22:44:30 +0200 Subject: [PATCH 12/14] Some example changes --- resources/init/{main.mns => main.mnc} | 0 resources/init/mod.mon | 20 +++++++++++--------- src/cli/init/mod.rs | 15 ++++++++++++++- src/cli/options/init.rs | 3 +-- 4 files changed, 26 insertions(+), 12 deletions(-) rename resources/init/{main.mns => main.mnc} (100%) diff --git a/resources/init/main.mns b/resources/init/main.mnc similarity index 100% rename from resources/init/main.mns rename to resources/init/main.mnc diff --git a/resources/init/mod.mon b/resources/init/mod.mon index 995171d..3d7403f 100644 --- a/resources/init/mod.mon +++ b/resources/init/mod.mon @@ -1,14 +1,16 @@ -package: +package = { name = "$PROJECT_NAME$" version = "0.1.0" +} -targets: - $PROJECT_NAME$: - type: "executable" - path: "main.mns" - -dependencies: - test_dependency: "1.0.0" - +targets = { + $PROJECT_NAME$: { + type = "executable" + path = "main.mns" + } +} +dependencies = { + test_dependency = "1.0.0" +} diff --git a/src/cli/init/mod.rs b/src/cli/init/mod.rs index 3dba504..4ce91da 100644 --- a/src/cli/init/mod.rs +++ b/src/cli/init/mod.rs @@ -1,8 +1,21 @@ +use ::std::io::stdin; + use crate::cli::options::init::InitCmd; pub fn handle_init_cmd(args: &InitCmd) -> Result<(), String> { - let name = args.name.unwrap_or_else(|| "dirname".to_owned()); + let name = args.name.clone() + .unwrap_or_else(|| ask_name("project name? ")?); unimplemented!() } + +fn ask_name(prompt: &str) -> Result { + print!("{}", prompt); + let q: Name = Name::new(); + let mut name = String::with_capacity(16); + loop { + let input = stdin().read_line(&mut name); + + } +} diff --git a/src/cli/options/init.rs b/src/cli/options/init.rs index 5999677..3177c07 100644 --- a/src/cli/options/init.rs +++ b/src/cli/options/init.rs @@ -5,8 +5,7 @@ pub struct InitCmd { #[structopt( short = "n", long = "name", - help = "Name of the project to initialize. Defaults to directory name." + help = "Name of the project to initialize. If omitted, you will be asked interactively." )] pub name: Option, - } From be0cd541c99118abdade30c94d7a0652d43b97b2 Mon Sep 17 00:00:00 2001 From: Mark Verleg Date: Wed, 7 Jul 2021 22:46:01 +0200 Subject: [PATCH 13/14] Update Docker base image version --- ci/simple.Dockerfile | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/ci/simple.Dockerfile b/ci/simple.Dockerfile index dc410c1..443a7da 100644 --- a/ci/simple.Dockerfile +++ b/ci/simple.Dockerfile @@ -1,27 +1,10 @@ -FROM clux/muslrust:nightly-2021-04-24 AS build - -ENV RUST_BACKTRACE=1 - -RUN rustup component add rustfmt -RUN rustup component add clippy -RUN cargo install cargo-outdated -RUN cargo install cargo-audit -RUN cargo install cargo-deny -RUN cargo install cargo-tree - -# Add the files needed to compile dependencies. -COPY ./Cargo.toml Cargo.lock ./ -RUN mkdir -p src && \ - printf '\nfn main() {\n\tprintln!("something went wrong while building the docker image")\n}\n' | tee src/main.rs - -# Build the dependencies, remove Cargo files so they have to be re-added. -RUN cargo build --tests &&\ - cargo build --release &&\ - rm -rf Cargo.toml Cargo.lock src/ +#TODO @mark: why compile still takes >1 min each despite pre-compiled dependencies? +FROM mangocode/mango_daily_base:2021-06-27 AS build # Copy the actual code. -COPY ./Cargo.toml ./Cargo.lock ./deny.toml ./rustfmt.toml ./ +# exclude .lock file for now as it slows down dependencies +COPY ./Cargo.toml ./deny.toml ./rustfmt.toml ./ COPY ./src/ ./src # Build (for test) From 48e100b9da726813262a3a6e45d34d4e69edf0bb Mon Sep 17 00:00:00 2001 From: Mark Verleg Date: Wed, 7 Jul 2021 22:46:27 +0200 Subject: [PATCH 14/14] Upgrade Cargo dependencies --- .dockerignore | 2 +- .gitignore | 2 +- Cargo.lock | 133 ++++++++++++++++++++++++-------------------------- Cargo.toml | 6 +-- 4 files changed, 68 insertions(+), 75 deletions(-) diff --git a/.dockerignore b/.dockerignore index 30f3436..bcd167d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,10 +5,10 @@ # Now explicitly add the source code, Cargo files and readme: !Cargo.toml -!Cargo.lock !rustfmt.toml !deny.toml !src/ +!resources/ !README.rst !LICENSE.txt !ci/extra_checks.sh diff --git a/.gitignore b/.gitignore index 9e3dcf1..98ecab0 100644 --- a/.gitignore +++ b/.gitignore @@ -124,7 +124,7 @@ coverage # Bower dependency directory (https://bower.io/) bower_components -# node-waf configuration +# expression-waf configuration .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) diff --git a/Cargo.lock b/Cargo.lock index fcd52ad..60b092a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,12 +63,11 @@ dependencies = [ [[package]] name = "async-io" -version = "1.4.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bbfd5cf2794b1e908ea8457e6c45f8f8f1f6ec5f74617bf4662623f47503c3b" +checksum = "a811e6a479f2439f0c04038796b5cfb3d2ad56c230e0f2d3f7b04d68cfee607b" dependencies = [ "concurrent-queue", - "fastrand", "futures-lite", "libc", "log", @@ -149,12 +148,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "autocfg" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" - [[package]] name = "bincode" version = "1.3.3" @@ -207,9 +200,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.6.1" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" [[package]] name = "byte-tools" @@ -241,9 +234,9 @@ checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" [[package]] name = "cc" -version = "1.0.67" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" [[package]] name = "cfg-if" @@ -283,11 +276,10 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ - "autocfg", "cfg-if 1.0.0", "lazy_static", ] @@ -333,9 +325,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ "atty", "humantime", @@ -420,9 +412,9 @@ checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" [[package]] name = "futures-lite" -version = "1.11.3" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" dependencies = [ "fastrand", "futures-core", @@ -455,9 +447,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if 1.0.0", "libc", @@ -479,18 +471,18 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" dependencies = [ "unicode-segmentation", ] [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -605,9 +597,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.94" +version = "0.2.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" +checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" [[package]] name = "lock_api" @@ -727,9 +719,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "opaque-debug" @@ -803,9 +795,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] name = "pin-utils" @@ -815,14 +807,14 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "polling" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fc12d774e799ee9ebae13f4076ca003b40d18a11ac0f3641e6f899618580b7b" +checksum = "92341d779fa34ea8437ef4d82d440d5e1ce3f3ff7f824aa64424cd481f9a1f25" dependencies = [ "cfg-if 1.0.0", "libc", "log", - "wepoll-sys", + "wepoll-ffi", "winapi 0.3.9", ] @@ -858,9 +850,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ "unicode-xid", ] @@ -889,14 +881,14 @@ dependencies = [ [[package]] name = "rand" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", - "rand_chacha 0.3.0", - "rand_core 0.6.2", - "rand_hc 0.3.0", + "rand_chacha 0.3.1", + "rand_core 0.6.3", + "rand_hc 0.3.1", ] [[package]] @@ -911,12 +903,12 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.2", + "rand_core 0.6.3", ] [[package]] @@ -930,11 +922,11 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.2", + "getrandom 0.2.3", ] [[package]] @@ -948,18 +940,18 @@ dependencies = [ [[package]] name = "rand_hc" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ - "rand_core 0.6.2", + "rand_core 0.6.3", ] [[package]] name = "redox_syscall" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" dependencies = [ "bitflags", ] @@ -970,7 +962,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ - "getrandom 0.2.2", + "getrandom 0.2.3", "redox_syscall", ] @@ -1107,9 +1099,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.21" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" +checksum = "69b041cdcb67226aca307e6e7be44c8806423d83e018bd662360a93dabce4d71" dependencies = [ "clap", "lazy_static", @@ -1119,9 +1111,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" +checksum = "7813934aecf5f51a54775e00068c237de98489463968231a51746bbbc03f9c10" dependencies = [ "heck", "proc-macro-error", @@ -1132,9 +1124,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ "proc-macro2", "quote", @@ -1149,7 +1141,7 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ "cfg-if 1.0.0", "libc", - "rand 0.8.3", + "rand 0.8.4", "redox_syscall", "remove_dir_all", "winapi 0.3.9", @@ -1205,18 +1197,18 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" @@ -1244,11 +1236,12 @@ dependencies = [ [[package]] name = "value-bag" -version = "1.0.0-alpha.6" +version = "1.0.0-alpha.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b676010e055c99033117c2343b33a40a30b91fecd6c49055ac9cd2d6c305ab1" +checksum = "dd320e1520f94261153e96f7534476ad869c14022aee1e59af7c778075d840ae" dependencies = [ "ctor", + "version_check", ] [[package]] @@ -1358,10 +1351,10 @@ dependencies = [ ] [[package]] -name = "wepoll-sys" -version = "3.0.1" +name = "wepoll-ffi" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" dependencies = [ "cc", ] diff --git a/Cargo.toml b/Cargo.toml index 3f7ccd9..a270563 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,17 +17,17 @@ name = "mango" path = "src/main.rs" [dependencies] -serde = { version = "1.0.125", features = ["derive"] } +serde = { version = "1.0.126", features = ["derive"] } bincode = "1.3.3" serde_json = "1.0.64" dirs = "3.0.2" whoami = "1.1.2" -structopt = { version = "0.3.21", features = [ "paw" ] } +structopt = { version = "0.3.22", features = [ "paw" ] } lazy_static = "1.4.0" ws = "0.9.1" log = "0.4.14" async-std = "1.9.0" -env_logger = "0.8.3" +env_logger = "0.8.4" paw = "1.0.0" [dev-dependencies]