From e36c66529794982f953c7a77abb751e79ca5f2d3 Mon Sep 17 00:00:00 2001 From: Fabio Forni Date: Sat, 25 Jun 2022 12:39:30 +0200 Subject: [PATCH 1/2] data/macros/actions: Add support for cargo --- data/macros/actions/rust.yml | 20 ++++++++++++++++++++ data/macros/arch/aarch64.yml | 1 + data/macros/arch/emul32/x86_64.yml | 1 + data/macros/arch/x86.yml | 1 + data/macros/arch/x86_64-stage1.yml | 3 ++- data/macros/arch/x86_64.yml | 1 + 6 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 data/macros/actions/rust.yml diff --git a/data/macros/actions/rust.yml b/data/macros/actions/rust.yml new file mode 100644 index 0000000000..a5527f823b --- /dev/null +++ b/data/macros/actions/rust.yml @@ -0,0 +1,20 @@ +actions: + + # Fetch dependencies (crates). + - cargo_fetch: + command: | + cargo fetch --target %(rust_host_platform) + + # Build release-quality artifacts in offine mode. Deps must've been downloaded before. + - cargo_build: + command: | + cargo build --target %(rust_host_platform) --release --offline + + # NOTE: There is no `cargo_install` command, because it's not a + # `make install` equivalent. It' supposed to install artifacts into + # cargo's own toolset, addressed at developers. You'll have to move files yourself. + + # Test the release-quality artifacts. + - cargo_check: + command: | + cargo test --target %(rust_host_platform) --release --offline diff --git a/data/macros/arch/aarch64.yml b/data/macros/arch/aarch64.yml index 2aaa5e718a..1c9c81040a 100644 --- a/data/macros/arch/aarch64.yml +++ b/data/macros/arch/aarch64.yml @@ -10,6 +10,7 @@ definitions: - cpp : "%(compiler_cpp) -m64" - march : armv8-a+simd+fp+crypto - mtune : cortex-a72.cortex-a53 + - rust_host_platform : "aarch64-unknown-linux-gnu" flags: diff --git a/data/macros/arch/emul32/x86_64.yml b/data/macros/arch/emul32/x86_64.yml index 476ca11de9..02199cd636 100644 --- a/data/macros/arch/emul32/x86_64.yml +++ b/data/macros/arch/emul32/x86_64.yml @@ -10,6 +10,7 @@ definitions: - cpp : "%(compiler_cpp) -m32" - march : x86-64-v2 - mtune : ivybridge + - rust_host_platform : "i686-unknown-linux-gnu" flags: diff --git a/data/macros/arch/x86.yml b/data/macros/arch/x86.yml index d7300c8a1d..f1468236d2 100644 --- a/data/macros/arch/x86.yml +++ b/data/macros/arch/x86.yml @@ -10,6 +10,7 @@ definitions: - cpp : "%(compiler_cpp) -m32" - march : x86-64-v2 - mtune : ivybridge + - rust_host_platform : "i686-unknown-linux-gnu" flags: diff --git a/data/macros/arch/x86_64-stage1.yml b/data/macros/arch/x86_64-stage1.yml index a1e3b0b8c5..ffae88bc14 100644 --- a/data/macros/arch/x86_64-stage1.yml +++ b/data/macros/arch/x86_64-stage1.yml @@ -15,6 +15,7 @@ definitions: - cpp : "%(compiler_cpp)" - march : x86-64-v2 - mtune : ivybridge + - rust_host_platform : "x86_64-unknown-linux-gnu" - bootstrap_root : /bill flags: @@ -26,4 +27,4 @@ flags: defaultTuningGroups : - base - - optimize \ No newline at end of file + - optimize diff --git a/data/macros/arch/x86_64.yml b/data/macros/arch/x86_64.yml index 7e812f8bd9..f54e8c96f2 100644 --- a/data/macros/arch/x86_64.yml +++ b/data/macros/arch/x86_64.yml @@ -10,6 +10,7 @@ definitions: - cpp : "%(compiler_cpp)" - march : x86-64-v2 - mtune : ivybridge + - rust_host_platform : "x86_64-unknown-linux-gnu" flags: From 23dde8f9f5e131b70d989441a1c5bd2a97d286ba Mon Sep 17 00:00:00 2001 From: Fabio Forni Date: Sat, 25 Jun 2022 15:12:07 +0200 Subject: [PATCH 2/2] drafter: Add support for Cargo projects --- data/macros/actions/rust.yml | 4 +-- source/drafter/build/package.d | 6 ++++ source/drafter/build/rust.d | 60 ++++++++++++++++++++++++++++++++++ source/drafter/meson.build | 1 + source/drafter/package.d | 3 +- 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 source/drafter/build/rust.d diff --git a/data/macros/actions/rust.yml b/data/macros/actions/rust.yml index a5527f823b..595bb851d3 100644 --- a/data/macros/actions/rust.yml +++ b/data/macros/actions/rust.yml @@ -8,7 +8,7 @@ actions: # Build release-quality artifacts in offine mode. Deps must've been downloaded before. - cargo_build: command: | - cargo build --target %(rust_host_platform) --release --offline + cargo build --target %(rust_host_platform) --release --offline -j %(jobs) # NOTE: There is no `cargo_install` command, because it's not a # `make install` equivalent. It' supposed to install artifacts into @@ -17,4 +17,4 @@ actions: # Test the release-quality artifacts. - cargo_check: command: | - cargo test --target %(rust_host_platform) --release --offline + cargo test --target %(rust_host_platform) --release --offline -j %(jobs) -- --test-threads=%(jobs) diff --git a/source/drafter/build/package.d b/source/drafter/build/package.d index 9436e58598..28200dc883 100644 --- a/source/drafter/build/package.d +++ b/source/drafter/build/package.d @@ -19,6 +19,7 @@ public import drafter.build.autotools; public import drafter.build.cmake; public import drafter.build.meson; public import drafter.build.python; +public import drafter.build.rust; import std.traits : EnumMembers; import std.string : capitalize; @@ -77,6 +78,11 @@ public enum BuildType : string */ PythonSetuptools = "PythonSetuptools", + /** + * Uses cargo. + */ + Cargo = "cargo", + /** * Unsupported tooling */ diff --git a/source/drafter/build/rust.d b/source/drafter/build/rust.d new file mode 100644 index 0000000000..5d5e4ba2f4 --- /dev/null +++ b/source/drafter/build/rust.d @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: Zlib */ + +/** + * Drafter - Python integration + * + * Authors: © 2020-2022 Serpent OS Developers + * License: Zlib + */ + +module drafter.build.rust; + +import moss.deps.analysis; +import drafter : Drafter; +import drafter.build : BuildType; +import std.path : baseName; + +/** + * Discover Cargo projects. + */ +static private AnalysisReturn acceptCargo(scope Analyser an, ref FileInfo inpath) +{ + Drafter c = an.userdata!Drafter; + + switch (inpath.path.baseName) + { + case "Cargo.toml": + c.incrementBuildConfidence(BuildType.Cargo, 100); + return AnalysisReturn.IncludeFile; + default: + return AnalysisReturn.NextHandler; + } +} + +/** + * Handler for Cargo projects. + */ +public static AnalysisChain cargoChain = AnalysisChain("cargo", [&acceptCargo], 20); + +public struct CargoBuild +{ + string setup() + { + return "%cargo_fetch"; + } + + string build() + { + return "%cargo_build"; + } + + string install() + { + return null; + } + + string check() + { + return "%cargo_check"; + } +} diff --git a/source/drafter/meson.build b/source/drafter/meson.build index 42808872e9..9f453c2af5 100644 --- a/source/drafter/meson.build +++ b/source/drafter/meson.build @@ -5,6 +5,7 @@ libdrafter_sources = [ 'build/meson.d', 'build/package.d', 'build/python.d', + 'build/rust.d', 'license/engine.d', 'license/package.d', 'metadata/basic.d', diff --git a/source/drafter/package.d b/source/drafter/package.d index c5863aca4c..dde2786bc4 100644 --- a/source/drafter/package.d +++ b/source/drafter/package.d @@ -83,13 +83,14 @@ public final class Drafter analyser.addChain(mesonChain); analyser.addChain(cmakeChain); analyser.addChain(pythonChain); + analyser.addChain(cargoChain); analyser.addChain(licenseChain); controller.onFail.connect(&onFail); controller.onComplete.connect(&onComplete); _licenseEngine = new Engine(); auto licenseDir = thisExePath.dirName.buildNormalizedPath("..", - "share", "boulder", "licenses").absolutePath; + "share", "boulder", "licenses").absolutePath; _licenseEngine.loadFromDirectory(licenseDir); _licenses = new RedBlackTree!(string, "a < b", false); outputFile = File(outputPath, "w");