diff --git a/.gitignore b/.gitignore index a77c5b3..4dba5e9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ Weaver.toml Lingo.toml nix-build .idea - +.direnv result # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html diff --git a/Cargo.lock b/Cargo.lock index b35ae41..a0c1859 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,30 +4,68 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04" dependencies = [ "memchr", ] [[package]] -name = "anyhow" -version = "1.0.70" +name = "anstream" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +checksum = "6342bd4f5a1205d7f41e94a41a901f5647c938cdfa96036338e8533c9d6c2450" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] [[package]] -name = "atty" -version = "0.2.14" +name = "anstyle" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" + +[[package]] +name = "anstyle-parse" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" dependencies = [ - "hermit-abi", - "libc", - "winapi", + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +dependencies = [ + "anstyle", + "windows-sys", ] +[[package]] +name = "anyhow" +version = "1.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" + [[package]] name = "autocfg" version = "1.1.0" @@ -63,42 +101,51 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.2.23" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +checksum = "8a1f23fa97e1d1641371b51f35535cb26959b8e27ab50d167a8b996b5bada819" dependencies = [ - "atty", - "bitflags", + "clap_builder", "clap_derive", - "clap_lex", - "indexmap", "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fdc5d93c358224b4d6867ef1356d740de2303e9892edc06c5340daeccd96bab" +dependencies = [ + "anstream", + "anstyle", + "bitflags", + "clap_lex", "strsim", - "termcolor", - "textwrap", ] [[package]] name = "clap_derive" -version = "3.2.18" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" dependencies = [ "heck", - "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] +checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "crossbeam" @@ -116,9 +163,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ "cfg-if", "crossbeam-utils", @@ -169,9 +216,30 @@ dependencies = [ [[package]] name = "dunce" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c" +checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" + +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] [[package]] name = "form_urlencoded" @@ -194,9 +262,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" dependencies = [ "cfg-if", "libc", @@ -205,9 +273,9 @@ dependencies = [ [[package]] name = "git2" -version = "0.16.1" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf7f68c2995f392c49fffb4f95ae2c873297830eb25c6bc4c114ce8f4562acc" +checksum = "8b7905cdfe33d31a88bb2e8419ddd054451f5432d1da9eaf2ac7804ee1ea12d5" dependencies = [ "bitflags", "libc", @@ -232,12 +300,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" [[package]] name = "idna" @@ -259,6 +324,29 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "io-lifetimes" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" +dependencies = [ + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys", +] + [[package]] name = "itoa" version = "1.0.6" @@ -276,15 +364,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.140" +version = "0.2.142" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" [[package]] name = "libgit2-sys" -version = "0.14.2+1.5.1" +version = "0.15.1+1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f3d95f6b51075fe9810a7ae22c7095f12b98005ab364d8544797a825ce946a4" +checksum = "fb4577bde8cdfc7d6a2a4bcb7b049598597de33ffd337276e9c7db6cd4a2cee7" dependencies = [ "cc", "libc", @@ -296,9 +384,9 @@ dependencies = [ [[package]] name = "libssh2-sys" -version = "0.2.23" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b094a36eb4b8b8c8a7b4b8ae43b2944502be3e59cd87687595cf6b0a71b3f4ca" +checksum = "2dc8a030b787e2119a731f1951d6a773e2280c660f8ec4b0f5e1505a386e71ee" dependencies = [ "cc", "libc", @@ -310,9 +398,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +checksum = "56ee889ecc9568871456d42f603d6a0ce59ff328d291063a45cbdf0036baf6db" dependencies = [ "cc", "libc", @@ -346,6 +434,12 @@ dependencies = [ "toml", ] +[[package]] +name = "linux-raw-sys" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b64f40e5e03e0d54f03845c8197d0291253cdbedfb1cb46b13c2c117554a9f4c" + [[package]] name = "log" version = "0.4.17" @@ -390,11 +484,10 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.83" +version = "0.9.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "666416d899cf077260dac8698d60a60b435a46d57e82acb1be3d0dad87284e5b" +checksum = "8e17f59264b2809d77ae94f0e1ebabc434773f370d6ca667bd223ea10e06cc7e" dependencies = [ - "autocfg", "cc", "libc", "pkg-config", @@ -413,12 +506,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "os_str_bytes" -version = "6.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" - [[package]] name = "percent-encoding" version = "2.2.0" @@ -451,44 +538,20 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" -version = "1.0.54" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ "unicode-ident", ] [[package]] name = "quick-xml" -version = "0.28.1" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5c1a97b1bc42b1d550bfb48d4262153fe400a12bab1511821736f7eac76d7e2" +checksum = "0ce5e73202a820a31f8a0ee32ada5e21029c81fd9e3ebf668a40832e4219d9d1" dependencies = [ "memchr", ] @@ -552,9 +615,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.3" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" +checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" dependencies = [ "aho-corasick", "memchr", @@ -563,9 +626,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.29" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" [[package]] name = "run_script" @@ -576,6 +639,20 @@ dependencies = [ "fsio", ] +[[package]] +name = "rustix" +version = "0.37.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bbfc1d1c7c40c01715f47d71444744a81669ca84e8b63e25a55e169b1f86433" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.13" @@ -596,26 +673,26 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.158" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" +checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" [[package]] name = "serde_derive" -version = "1.0.158" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" +checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" dependencies = [ "proc-macro2", "quote", - "syn 2.0.10", + "syn", ] [[package]] name = "serde_json" -version = "1.0.94" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" dependencies = [ "itoa", "ryu", @@ -630,35 +707,15 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "syn" -version = "2.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aad1363ed6d37b84299588d62d3a7d95b5a5c2d9aad5c85609fda12afaa1f40" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "termcolor" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" -dependencies = [ - "winapi-util", -] - [[package]] name = "termion" version = "1.5.6" @@ -671,12 +728,6 @@ dependencies = [ "redox_termios", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "time" version = "0.3.20" @@ -770,16 +821,16 @@ dependencies = [ ] [[package]] -name = "vcpkg" -version = "0.2.15" +name = "utf8parse" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] -name = "version_check" -version = "0.9.4" +name = "vcpkg" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "wasi" @@ -804,16 +855,73 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "winapi-util" -version = "0.1.5" +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "winapi", + "windows-targets", ] [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows-targets" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/Cargo.toml b/Cargo.toml index a267d8e..5679062 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] -clap = { version = "3.1", features = ["derive"] } +clap = { version = "4.1", features = ["derive"] } os-version = "0.2" regex = "1" diff --git a/defaults/HelloC.lf b/defaults/HelloC.lf new file mode 100644 index 0000000..9803098 --- /dev/null +++ b/defaults/HelloC.lf @@ -0,0 +1,8 @@ +target C; + +main reactor { + reaction (startup) {= + lf_print("Hello World!"); + =} +} + diff --git a/defaults/Main.lf b/defaults/HelloCpp.lf similarity index 100% rename from defaults/Main.lf rename to defaults/HelloCpp.lf diff --git a/src/args.rs b/src/args.rs index 9bda05d..0f5a487 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,4 +1,5 @@ use clap::{Args, Parser, Subcommand}; +use serde_derive::{Deserialize, Serialize}; #[derive(Args, Debug)] pub struct BuildArgs { @@ -19,10 +20,42 @@ pub struct BuildArgs { pub lfc: Option, } +#[derive(clap::ValueEnum, Clone, Debug, Deserialize, Serialize)] +pub enum TargetLanguage { + C, + Cpp, + Rust, +} + +impl ToString for TargetLanguage { + fn to_string(&self) -> String { + match self { + TargetLanguage::C => "C".to_string(), + TargetLanguage::Cpp => "Cpp".to_string(), + TargetLanguage::Rust => "Rust".to_string(), + } + } +} + +#[derive(clap::ValueEnum, Clone, Debug, Deserialize, Serialize)] +pub enum Platform { + Native, + Zephyr, +} + +#[derive(Args, Debug)] +pub struct InitArgs { + #[clap(value_enum, short, long)] + pub language: Option, + + #[clap(value_enum, short, long)] + pub platform: Option, +} + #[derive(Subcommand, Debug)] pub enum Command { /// initializing a lingua-franca project - Init, + Init(InitArgs), /// compiling one ore multiple binaries in a lingua-franca package Build(BuildArgs), diff --git a/src/backends/lfc.rs b/src/backends/lfc.rs index 659f15a..969223e 100644 --- a/src/backends/lfc.rs +++ b/src/backends/lfc.rs @@ -23,6 +23,8 @@ impl Backend for LFC { let build_lambda = |main_reactor: &String| -> bool { println!("building main reactor: {}", &main_reactor); + // FIXME: What is this supposed to do? `lfc` does not have n `--output` argument + // also. Why isnt the lfc from the CLI `-l` used. let mut command = Command::new("lfc"); command.arg("--output"); command.arg("./"); diff --git a/src/lfc/mod.rs b/src/lfc/mod.rs index 49eadd5..7f98ba5 100644 --- a/src/lfc/mod.rs +++ b/src/lfc/mod.rs @@ -69,7 +69,7 @@ impl CodeGenerator { properties: HashMap, ) -> CodeGenerator { CodeGenerator { - lfc: lfc.unwrap_or(PathBuf::from("/")), + lfc: lfc.unwrap_or(PathBuf::from("/bin/lfc")), properties: LFCProperties::new(src, out, properties), } } @@ -78,13 +78,19 @@ impl CodeGenerator { // path to the src-gen directory let mut src_gen_directory = app.root_path.clone(); src_gen_directory.push(PathBuf::from("./src-gen")); + + // FIXME: This validation should be somewhere else + if !self.lfc.exists() { + panic!("lfc not found at `{}`", &self.lfc.display()); + } + println!( - "generating code ... {}/bin/lfc --json={}", + "Invoking code-generator: `{} --json={}`", &self.lfc.display(), self.properties ); - let mut command = Command::new(format!("{}/bin/lfc", &self.lfc.display())); + let mut command = Command::new(format!("{}", &self.lfc.display())); command.arg(format!("--json={}", self.properties)); match run_and_capture(&mut command) { diff --git a/src/main.rs b/src/main.rs index 481b8a9..f72d01e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,11 +59,11 @@ fn main() { // we match on a tuple here match (wrapped_config, args.command) { - (_, ConsoleCommand::Init) => { - let initial_config = package::ConfigFile::new(); + (_, ConsoleCommand::Init(init_config)) => { + let initial_config = package::ConfigFile::new(init_config); let toml_path = format!("{}/Lingo.toml", PACKAGE_FILE); initial_config.write(Path::new(&toml_path)); - package::ConfigFile::setup_example(); + initial_config.setup_example(); } (Some(file_config), ConsoleCommand::Build(build_command_args)) => { let mut working_path = lingo_path.unwrap(); diff --git a/src/package/mod.rs b/src/package/mod.rs index fe3ac8a..f82273b 100644 --- a/src/package/mod.rs +++ b/src/package/mod.rs @@ -1,11 +1,18 @@ -use crate::util::analyzer; +use crate::args::{InitArgs, Platform, TargetLanguage}; +use crate::util::{analyzer, copy_recursively}; use serde_derive::{Deserialize, Serialize}; use std::collections::HashMap; -use std::fs::{read_to_string, write}; +use std::fs::{read_to_string, remove_dir_all, remove_file, write}; use std::path::{Path, PathBuf}; +use git2::Repository; + +fn is_valid_location_for_project(path: &std::path::Path) -> bool { + !path.join("src").exists() && !path.join(".git").exists() && !path.join("application").exists() +} + #[derive(Deserialize, Serialize, Clone)] pub struct AppVec { pub app: Vec, @@ -48,7 +55,9 @@ pub struct AppFile { pub main_reactor: Option, /// target of the app - pub target: String, + pub target: TargetLanguage, + + pub platform: Platform, pub dependencies: HashMap, @@ -62,7 +71,8 @@ pub struct App { pub name: String, pub main_reactor: String, - pub target: String, + pub target: TargetLanguage, + pub platform: Platform, pub dependencies: HashMap, pub properties: HashMap, @@ -98,7 +108,7 @@ pub struct PackageDescription { } impl ConfigFile { - pub fn new() -> ConfigFile { + pub fn new(init_args: InitArgs) -> ConfigFile { let _main_reactor = if !std::path::Path::new("./src").exists() { vec![String::from("Main")] } else { @@ -125,7 +135,14 @@ impl ConfigFile { apps: vec![AppFile { name: None, main_reactor: None, - target: "cpp".to_string(), + target: init_args.language.unwrap_or({ + // Target langauge for Zephyr is C, else Cpp. + match init_args.platform { + Some(Platform::Zephyr) => TargetLanguage::C, + _ => TargetLanguage::Cpp, + } + }), + platform: init_args.platform.unwrap_or(Platform::Native), dependencies: HashMap::new(), properties: HashMap::new(), }], @@ -149,12 +166,48 @@ impl ConfigFile { } } - pub fn setup_example() { - if !std::path::Path::new("./src").exists() { - std::fs::create_dir_all("./src").expect("Cannot create target directory"); - let hello_world_code: &'static str = include_str!("../../defaults/Main.lf"); - write(Path::new("./src/Main.lf"), hello_world_code) - .expect("cannot write Main.lf file!"); + // Sets up a standard LF project for "native" development and deployment + pub fn setup_native(&self) { + std::fs::create_dir_all("./src").expect("Cannot create target directory"); + let hello_world_code: &'static str = match self.apps[0].target { + TargetLanguage::Cpp => include_str!("../../defaults/HelloCpp.lf"), + TargetLanguage::C => include_str!("../../defaults/HelloC.lf"), + _ => panic!("Target langauge not supported yet"), // FIXME: Add examples for other programs + }; + + write(Path::new("./src/Main.lf"), hello_world_code).expect("cannot write Main.lf file!"); + } + + // Sets up a LF project with Zephyr as the target platform. + pub fn setup_zephyr(&self) { + // Clone lf-west-template into a temporary directory + let tmp_path = Path::new("zephyr_tmp"); + if tmp_path.exists() { + remove_dir_all(tmp_path).expect("Could not remove temporarily cloned repository"); + } + let url = "https://github.com/lf-lang/lf-west-template"; + let _repo = match Repository::clone(url, tmp_path) { + Ok(repo) => repo, + Err(e) => panic!("failed to clone: {}", e), // FIXME: How to handle errors? + }; + + // Copy the cloned template repo into the project directory + copy_recursively(tmp_path, Path::new(".")).expect("Could not copy cloned repo"); + + // Remove .git, .gitignore ad temporary folder + remove_file(".gitignore").expect("Could not remove .gitignore"); + remove_dir_all(Path::new(".git")).expect("Could not remove .git directory"); + remove_dir_all(tmp_path).expect("Could not remove temporarily cloned repository"); + } + + pub fn setup_example(&self) { + if is_valid_location_for_project(Path::new(".")) { + match self.apps[0].platform { + Platform::Native => self.setup_native(), + Platform::Zephyr => self.setup_zephyr(), + } + } else { + panic!("Failed to initilize project, invalid location"); // FIXME: Handle properly } } @@ -171,8 +224,9 @@ impl ConfigFile { main_reactor: app .main_reactor .clone() - .unwrap_or("src/main.lf".to_string()), + .unwrap_or("src/Main.lf".to_string()), // FIXME: The default should be that it searches the `src` directory for a main reactor target: app.target.clone(), + platform: app.platform.clone(), dependencies: app.dependencies.clone(), properties: app.properties.clone(), }) @@ -180,9 +234,3 @@ impl ConfigFile { } } } - -impl Default for ConfigFile { - fn default() -> Self { - Self::new() - } -} diff --git a/src/util/mod.rs b/src/util/mod.rs index 418b977..5a0cfaa 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -4,7 +4,7 @@ pub mod command_line; use crate::package::App; use regex::Regex; use std::path::{Path, PathBuf}; - +use std::{fs, io}; /// given is some list of build targets which are filtered by the binary regex /// the lambda f is invoked on every element of the remaining elements which fit /// the regex. @@ -66,3 +66,19 @@ pub fn find_toml(input_path: &Path) -> Option { None => None, } } + +/// Copy files from source to destination recursively. +// Copied from https://nick.groenen.me/notes/recursively-copy-files-in-rust/ +pub fn copy_recursively(source: impl AsRef, destination: impl AsRef) -> io::Result<()> { + fs::create_dir_all(&destination)?; + for entry in fs::read_dir(source)? { + let entry = entry?; + let filetype = entry.file_type()?; + if filetype.is_dir() { + copy_recursively(entry.path(), destination.as_ref().join(entry.file_name()))?; + } else { + fs::copy(entry.path(), destination.as_ref().join(entry.file_name()))?; + } + } + Ok(()) +}