From 41ba05ae5b2f6b0d2a40912beefacd7bb5942ea3 Mon Sep 17 00:00:00 2001 From: Robert Bastian <4706271+robertbastian@users.noreply.github.com> Date: Sat, 21 Oct 2023 19:51:16 +0200 Subject: [PATCH] Versioning `diplomat-tool` through Cargo (#4197) --- .github/workflows/build-test.yml | 26 ----- CONTRIBUTING.md | 1 - Cargo.lock | 177 ++++++++++++++++++++++++++++++- Cargo.toml | 9 +- Makefile.toml | 2 +- ffi/capi/c/README.md | 1 - ffi/capi/cpp/README.md | 1 - ffi/capi/js/README.md | 1 - ffi/gn/.cargo/config | 4 +- ffi/gn/Cargo.lock | 6 +- tools/diplomat-gen/Cargo.toml | 20 ++++ tools/diplomat-gen/LICENSE | 44 ++++++++ tools/diplomat-gen/src/main.rs | 38 +++++++ tools/make/ffi.toml | 118 ++------------------- 14 files changed, 293 insertions(+), 155 deletions(-) create mode 100644 tools/diplomat-gen/Cargo.toml create mode 100644 tools/diplomat-gen/LICENSE create mode 100644 tools/diplomat-gen/src/main.rs diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 06cc75d7277..7986e84b004 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -551,32 +551,6 @@ jobs: - name: Show the selected Rust toolchain run: rustup show - # Job-specific dependencies - - name: Run diplomat-get-rev to ensure it works - id: diplomat-getrev-check - run: cargo make --loglevel error diplomat-get-rev - - name: Get Diplomat version - id: diplomat-version - run: | - echo "::set-output name=rev::$(cargo make --loglevel error diplomat-get-rev | tr -d '[:space:]')" - shell: bash - - name: Attempt to load cached Diplomat - uses: actions/cache@v3 - id: diplomat-cache - with: - path: | - ~/.cargo/bin/diplomat-tool - ~/.cargo/bin/diplomat-tool.exe - key: ${{ runner.os }}-diplomat-${{ steps.diplomat-version.outputs.rev }} - - - name: Install Diplomat (git hash) - if: steps.diplomat-cache.outputs.cache-hit != 'true' && !contains(steps.diplomat-version.outputs.rev, '.') - run: cargo +stable install --git https://github.com/rust-diplomat/diplomat.git --rev ${{ steps.diplomat-version.outputs.rev }} diplomat-tool - - - name: Install Diplomat (versioned) - if: steps.diplomat-cache.outputs.cache-hit != 'true' && contains(steps.diplomat-version.outputs.rev, '.') - run: cargo +stable install --git https://github.com/rust-diplomat/diplomat.git --version ${{ steps.diplomat-version.outputs.rev }} diplomat-tool - # Actual job - name: Run `cargo make ci-job-diplomat` run: cargo make ci-job-diplomat diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8aaa1ac2933..13f25babfe2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -90,7 +90,6 @@ Our wider testsuite is organized as `ci-job-foo` make tasks corresponding to eac + Requires Node.js version 16.18.0. This may not the one offered by the package manager; get it from the NodeJS website or `nvm`. - `ci-job-nostd`: Builds ICU4X for a `#[no_std]` target to verify that it's compatible. - `ci-job-diplomat`: Verifies that diplomat-generated bindings are up to date. - + Requires [`Diplomat`](https://github.com/rust-diplomat/diplomat) installed at the appropriate version: `cargo make diplomat-install`. - `ci-job-gn`: Verifies that the GN wrapper is up to date. + Requires GN to be installed: `cargo make gn-install`. diff --git a/Cargo.lock b/Cargo.lock index 50e937485e6..6eabb28687f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -98,6 +98,50 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "askama" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28" +dependencies = [ + "askama_derive", + "askama_escape", + "humansize", + "num-traits", + "percent-encoding", +] + +[[package]] +name = "askama_derive" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a0fc7dcf8bd4ead96b1d36b41df47c14beedf7b0301fc543d8f2384e66a2ec0" +dependencies = [ + "askama_parser", + "basic-toml", + "mime", + "mime_guess", + "proc-macro2", + "quote", + "serde", + "syn 2.0.37", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_parser" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c268a96e01a4c47c8c5c2472aaa570707e006a875ea63e819f75474ceedaf7b4" +dependencies = [ + "nom", +] + [[package]] name = "atoi" version = "1.0.0" @@ -182,6 +226,15 @@ version = "0.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" +[[package]] +name = "basic-toml" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bfc506e7a2370ec239e1d072507b2a80c833083699d3c6fa176fbb4de8448c6" +dependencies = [ + "serde", +] + [[package]] name = "bies" version = "0.2.1" @@ -343,9 +396,14 @@ version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ + "atty", "bitflags 1.3.2", + "clap_derive 3.2.25", "clap_lex 0.2.4", "indexmap", + "once_cell", + "strsim", + "termcolor", "textwrap", ] @@ -356,7 +414,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "046ae530c528f252094e4a77886ee1374437744b2bff1497aa898bbddbbb29b3" dependencies = [ "clap_builder", - "clap_derive", + "clap_derive 4.2.0", "once_cell", ] @@ -373,6 +431,19 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_derive" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" +dependencies = [ + "heck 0.4.1", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "clap_derive" version = "4.2.0" @@ -728,7 +799,7 @@ dependencies = [ [[package]] name = "diplomat" version = "0.6.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=5091e173fb2dea945ac7a7f0cba5d41288afbf00#5091e173fb2dea945ac7a7f0cba5d41288afbf00" +source = "git+https://github.com/rust-diplomat/diplomat?rev=354307d4a519a3f42a9dc744ea0d64d766431d1d#354307d4a519a3f42a9dc744ea0d64d766431d1d" dependencies = [ "diplomat_core", "proc-macro2", @@ -736,19 +807,47 @@ dependencies = [ "syn 2.0.37", ] +[[package]] +name = "diplomat-gen" +version = "0.0.0" +dependencies = [ + "diplomat-tool", +] + [[package]] name = "diplomat-runtime" version = "0.6.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=5091e173fb2dea945ac7a7f0cba5d41288afbf00#5091e173fb2dea945ac7a7f0cba5d41288afbf00" +source = "git+https://github.com/rust-diplomat/diplomat?rev=354307d4a519a3f42a9dc744ea0d64d766431d1d#354307d4a519a3f42a9dc744ea0d64d766431d1d" dependencies = [ "log", ] +[[package]] +name = "diplomat-tool" +version = "0.6.0" +source = "git+https://github.com/rust-diplomat/diplomat?rev=354307d4a519a3f42a9dc744ea0d64d766431d1d#354307d4a519a3f42a9dc744ea0d64d766431d1d" +dependencies = [ + "askama", + "clap 3.2.25", + "colored", + "diplomat_core", + "displaydoc", + "heck 0.4.1", + "indenter", + "pulldown-cmark", + "quote", + "serde", + "syn 2.0.37", + "syn-inline-mod", + "toml", +] + [[package]] name = "diplomat_core" version = "0.6.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=5091e173fb2dea945ac7a7f0cba5d41288afbf00#5091e173fb2dea945ac7a7f0cba5d41288afbf00" +source = "git+https://github.com/rust-diplomat/diplomat?rev=354307d4a519a3f42a9dc744ea0d64d766431d1d#354307d4a519a3f42a9dc744ea0d64d766431d1d" dependencies = [ + "displaydoc", "lazy_static", "proc-macro2", "quote", @@ -1041,6 +1140,15 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + [[package]] name = "getrandom" version = "0.2.10" @@ -1180,6 +1288,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "humansize" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" +dependencies = [ + "libm", +] + [[package]] name = "iai" version = "0.1.1" @@ -2222,6 +2339,22 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2565,6 +2698,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "pulldown-cmark" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" +dependencies = [ + "bitflags 1.3.2", + "getopts", + "memchr", + "unicase", +] + [[package]] name = "quote" version = "1.0.33" @@ -3263,6 +3408,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "termcolor" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +dependencies = [ + "winapi-util", +] + [[package]] name = "textwrap" version = "0.16.0" @@ -3468,6 +3622,15 @@ dependencies = [ "walkdir", ] +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.13" @@ -3495,6 +3658,12 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + [[package]] name = "unicode-xid" version = "0.2.4" diff --git a/Cargo.toml b/Cargo.toml index 871579be789..bf5c7ec3639 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,6 +97,7 @@ members = [ "tools/benchmark/macros", "tools/benchmark/memory", "tools/depcheck", + "tools/diplomat-gen", "tools/ffi_coverage", "tools/testdata-scripts", ] @@ -229,12 +230,12 @@ icu_benchmark_macros = { path = "tools/benchmark/macros" } # ffi_coverage never used as a dep # testdata-scripts never used as a dep -# Run `cargo make diplomat-install` to get the right diplomat binary installed # The version here can either be a `version = ".."` spec or `git = "https://github.com/rust-diplomat/diplomat", rev = ".."` # Diplomat must be published preceding a new ICU4X release but may use git versions in between -diplomat = { git = "https://github.com/rust-diplomat/diplomat", rev = "5091e173fb2dea945ac7a7f0cba5d41288afbf00" } -diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "5091e173fb2dea945ac7a7f0cba5d41288afbf00" } -diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "5091e173fb2dea945ac7a7f0cba5d41288afbf00" } +diplomat = { git = "https://github.com/rust-diplomat/diplomat", rev = "354307d4a519a3f42a9dc744ea0d64d766431d1d" } +diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "354307d4a519a3f42a9dc744ea0d64d766431d1d" } +diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "354307d4a519a3f42a9dc744ea0d64d766431d1d" } +diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat", rev = "354307d4a519a3f42a9dc744ea0d64d766431d1d" } # LTO is needed for WASM and other size-optimized builds, # and it improve the performance of benchmarks diff --git a/Makefile.toml b/Makefile.toml index c2604f54246..5cbc0739f80 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -250,12 +250,12 @@ dependencies = [ "ci-job-test", "ci-job-test-docs", "ci-job-check-tutorials-cratesio", + "ci-job-diplomat", "ci-job-testdata", "ci-job-msrv-features", "ci-job-full-datagen", # Needs tools other than Cargo to be installed - "ci-job-diplomat", "ci-job-test-c", "ci-job-test-js", "ci-job-gn", diff --git a/ffi/capi/c/README.md b/ffi/capi/c/README.md index c0bfbeca195..3b8ccb025cf 100644 --- a/ffi/capi/c/README.md +++ b/ffi/capi/c/README.md @@ -3,7 +3,6 @@ This folder contains the C FFI for ICU4X. To re-generate the bindings run: ```sh -cargo make diplomat-install cargo make diplomat-gen-c ``` diff --git a/ffi/capi/cpp/README.md b/ffi/capi/cpp/README.md index 0fd964e92ed..6eda457ddd4 100644 --- a/ffi/capi/cpp/README.md +++ b/ffi/capi/cpp/README.md @@ -3,7 +3,6 @@ This folder contains the C++ FFI for ICU4X. To re-generate the bindings run: ```sh -cargo make diplomat-install cargo make diplomat-gen-cpp ``` diff --git a/ffi/capi/js/README.md b/ffi/capi/js/README.md index 7bc93e47d76..8b720510913 100644 --- a/ffi/capi/js/README.md +++ b/ffi/capi/js/README.md @@ -3,7 +3,6 @@ This folder contains the JavaScript/TypeScript FFI for ICU4X. To re-generate the bindings run: ```sh -cargo make diplomat-install cargo make diplomat-gen-js ``` diff --git a/ffi/gn/.cargo/config b/ffi/gn/.cargo/config index ec3206b2233..c602538edc7 100644 --- a/ffi/gn/.cargo/config +++ b/ffi/gn/.cargo/config @@ -6,9 +6,9 @@ [source.crates-io] replace-with = "vendored-sources" -[source."git+https://github.com/rust-diplomat/diplomat?rev=5091e173fb2dea945ac7a7f0cba5d41288afbf00"] +[source."git+https://github.com/rust-diplomat/diplomat?rev=354307d4a519a3f42a9dc744ea0d64d766431d1d"] git = "https://github.com/rust-diplomat/diplomat" -rev = "5091e173fb2dea945ac7a7f0cba5d41288afbf00" +rev = "354307d4a519a3f42a9dc744ea0d64d766431d1d" replace-with = "vendored-sources" [source.vendored-sources] diff --git a/ffi/gn/Cargo.lock b/ffi/gn/Cargo.lock index c45b452d176..d2de6d3e53b 100644 --- a/ffi/gn/Cargo.lock +++ b/ffi/gn/Cargo.lock @@ -120,7 +120,7 @@ checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" [[package]] name = "diplomat" version = "0.6.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=5091e173fb2dea945ac7a7f0cba5d41288afbf00#5091e173fb2dea945ac7a7f0cba5d41288afbf00" +source = "git+https://github.com/rust-diplomat/diplomat?rev=354307d4a519a3f42a9dc744ea0d64d766431d1d#354307d4a519a3f42a9dc744ea0d64d766431d1d" dependencies = [ "diplomat_core", "proc-macro2", @@ -131,12 +131,12 @@ dependencies = [ [[package]] name = "diplomat-runtime" version = "0.6.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=5091e173fb2dea945ac7a7f0cba5d41288afbf00#5091e173fb2dea945ac7a7f0cba5d41288afbf00" +source = "git+https://github.com/rust-diplomat/diplomat?rev=354307d4a519a3f42a9dc744ea0d64d766431d1d#354307d4a519a3f42a9dc744ea0d64d766431d1d" [[package]] name = "diplomat_core" version = "0.6.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=5091e173fb2dea945ac7a7f0cba5d41288afbf00#5091e173fb2dea945ac7a7f0cba5d41288afbf00" +source = "git+https://github.com/rust-diplomat/diplomat?rev=354307d4a519a3f42a9dc744ea0d64d766431d1d#354307d4a519a3f42a9dc744ea0d64d766431d1d" dependencies = [ "lazy_static", "proc-macro2", diff --git a/tools/diplomat-gen/Cargo.toml b/tools/diplomat-gen/Cargo.toml new file mode 100644 index 00000000000..33e0dca67a2 --- /dev/null +++ b/tools/diplomat-gen/Cargo.toml @@ -0,0 +1,20 @@ +# This file is part of ICU4X. For terms of use, please see the file +# called LICENSE at the top level of the ICU4X source tree +# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +[package] +name = "diplomat-gen" +version = "0.0.0" +publish = false + +rust-version.workspace = true +authors.workspace = true +edition.workspace = true +repository.workspace = true +homepage.workspace = true +license-file.workspace = true +categories.workspace = true +include.workspace = true + +[dependencies] +diplomat-tool.workspace = true diff --git a/tools/diplomat-gen/LICENSE b/tools/diplomat-gen/LICENSE new file mode 100644 index 00000000000..9845aa5f488 --- /dev/null +++ b/tools/diplomat-gen/LICENSE @@ -0,0 +1,44 @@ +UNICODE LICENSE V3 + +COPYRIGHT AND PERMISSION NOTICE + +Copyright © 2020-2023 Unicode, Inc. + +NOTICE TO USER: Carefully read the following legal agreement. BY +DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR +SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE +TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT +DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of data files and any associated documentation (the "Data Files") or +software and any associated documentation (the "Software") to deal in the +Data Files or Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, and/or sell +copies of the Data Files or Software, and to permit persons to whom the +Data Files or Software are furnished to do so, provided that either (a) +this copyright and permission notice appear with all copies of the Data +Files or Software, or (b) this copyright and permission notice appear in +associated Documentation. + +THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF +THIRD PARTY RIGHTS. + +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE +BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, +OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA +FILES OR SOFTWARE. + +Except as contained in this notice, the name of a copyright holder shall +not be used in advertising or otherwise to promote the sale, use or other +dealings in these Data Files or Software without prior written +authorization of the copyright holder. + +— + +Portions of ICU4X may have been adapted from ICU4C and/or ICU4J. +ICU 1.8.1 to ICU 57.1 © 1995-2016 International Business Machines Corporation and others. diff --git a/tools/diplomat-gen/src/main.rs b/tools/diplomat-gen/src/main.rs new file mode 100644 index 00000000000..87fc804d644 --- /dev/null +++ b/tools/diplomat-gen/src/main.rs @@ -0,0 +1,38 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +use std::path::Path; + +fn main() -> std::io::Result<()> { + let capi = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../../ffi/capi")); + + let Some(lang) = std::env::args().nth(1) else { + panic!("Missing argument "); + }; + + diplomat_tool::gen( + &capi.join("src/lib.rs"), + &lang, + &{ + let include = capi.join(&lang).join("include"); + std::fs::remove_dir_all(&include)?; + std::fs::create_dir(&include)?; + include + }, + if lang == "cpp" || lang == "js" { + let docs = capi.join(&lang).join("docs/source"); + let conf = std::fs::read_to_string(docs.join("conf.py"))?; + std::fs::remove_dir_all(&docs)?; + std::fs::create_dir(&docs)?; + std::fs::write(docs.join("conf.py"), conf)?; + Some(docs) + } else { + None + } + .as_deref(), + &Default::default(), + None, + false, + ) +} diff --git a/tools/make/ffi.toml b/tools/make/ffi.toml index 9ef00651064..4e90450891b 100644 --- a/tools/make/ffi.toml +++ b/tools/make/ffi.toml @@ -100,62 +100,27 @@ script = ''' exit_on_error true code = exec --get-exit-code git diff --exit-code -- ffi/capi if ${code} - trigger_error "Diplomat bindings need to be regenerated. Please run `cargo make diplomat-install`, then `cargo make diplomat-gen`, and commit. (Testing against different Diplomat versions may omit install step.)" + trigger_error "Diplomat bindings need to be regenerated. Please run `cargo make diplomat-gen` and commit. (Testing against different Diplomat versions may omit install step.)" end ''' [tasks.diplomat-gen-c] description = "Generate C headers for the FFI with Diplomat" category = "ICU4X Development" -script_runner = "@duckscript" -script = ''' -exit_on_error true -cd ffi/capi - -# Duckscript doesn't support globs in rm, so we delete the dir -rm -r ./c/include/ -mkdir ./c/include -exec --fail-on-error diplomat-tool c ./c/include -''' +command = "cargo" +args = ["run", "-p", "diplomat-gen", "c"] [tasks.diplomat-gen-cpp] description = "Generate C++ headers for the FFI with Diplomat" category = "ICU4X Development" -script_runner = "@duckscript" -script = ''' -exit_on_error true -cd ffi/capi - -# Duckscript doesn't support globs in rm, so we delete the dir. -# Preserve conf.py across the deletion. -conf_py = readfile ./cpp/docs/source/conf.py -rm -r ./cpp/include -mkdir ./cpp/include -rm -r ./cpp/docs/source -mkdir ./cpp/docs/source -writefile ./cpp/docs/source/conf.py ${conf_py} -exec --fail-on-error diplomat-tool cpp ./cpp/include --docs ./cpp/docs/source -''' +command = "cargo" +args = ["run", "-p", "diplomat-gen", "cpp"] [tasks.diplomat-gen-js] description = "Generate JS bindings for the FFI with Diplomat" category = "ICU4X Development" -script_runner = "bash" -script = ''' -set -e -cd ffi/capi - -# Duckscript doesn't support globs in rm, so we delete the dir. -# Preserve conf.py across the deletion. -conf_py=$(<./js/docs/source/conf.py) -rm -r ./js/include -mkdir ./js/include -rm -r ./js/docs/source -mkdir ./js/docs/source -echo "$conf_py" > ./js/docs/source/conf.py - -diplomat-tool js ./js/include/ --docs ./js/docs/source -''' +command = "cargo" +args = ["run", "-p", "diplomat-gen", "js"] # Diplomat coverage @@ -185,75 +150,6 @@ end # Install tasks -# These tasks need a minimum version of cargo-make. Configs within cargo-make -# task stanzas such as this allow setting the minimum version of deps (including -# min version for cargo-make itself). But cargo-make might only be applying -# such dep upgrades defined in the `install_crate` field after the task script -# has run. -[tasks.cargo-make-min-version] -description = "Verify that the minimum version of cargo-make exists" -category = "ICU4X Development" -install_crate = { crate_name = "cargo-make", binary = "cargo", test_arg = ["make", "--version"], min_version = "0.36.2" } - -[tasks.diplomat-install] -description = "Install Diplomat at current Diplomat revision" -category = "ICU4X Development" -dependencies = [ "cargo-make-min-version" ] -script_runner = "@duckscript" -script = ''' -exit_on_error true -rev = exec --fail-on-error cargo make --loglevel error diplomat-get-rev -rev = trim ${rev.stdout} -if contains ${rev} "." - echo "Installing Diplomat version ${rev}" - exec --fail-on-error cargo install --version ${rev} diplomat-tool -f - -else - echo "Installing Diplomat rev ${rev}" - exec --fail-on-error cargo install --git https://github.com/rust-diplomat/diplomat.git --rev ${rev} diplomat-tool -f -end -''' - -[tasks.diplomat-get-rev] -description = "Get current Diplomat revision" -category = "ICU4X Development" -dependencies = [ "cargo-make-min-version" ] -script_runner = "@duckscript" -script = ''' -exit_on_error true -metadata = exec --fail-on-error cargo metadata -metadata = set ${metadata.stdout} -# Parse output -metadata = json_parse --collection ${metadata} -# packages = metadata.packages -packages = map_get ${metadata} packages -for pkg in ${packages} - # find pkg.name - name = map_get ${pkg} name - # check if it is "diplomat" - e = eq ${name} "diplomat" - if ${e} - # get pkg.source - source = map_get ${pkg} source - version = map_get ${pkg} version - # extract the bit between `rev=` and `#` - handle = split ${source} "rev=" - hash_len = array_length ${handle} - if eq ${hash_len} 2 - hash = array_get ${handle} 1 - release handle - handle = split ${hash} "#" - version = array_get ${handle} 0 - end - release handle - - # print it - echo ${version} - end -end -release --recursive ${metadata} -''' - [tasks.install-unknown-linux] description = "Installs the unknown-linux target" category = "ICU4X Development"