Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Add support for Cargo projects in Drafter and in action macros #67

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions data/macros/actions/rust.yml
Original file line number Diff line number Diff line change
@@ -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 -j %(jobs)

# 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 -j %(jobs) -- --test-threads=%(jobs)
1 change: 1 addition & 0 deletions data/macros/arch/aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
1 change: 1 addition & 0 deletions data/macros/arch/emul32/x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ definitions:
- cpp : "%(compiler_cpp) -m32"
- march : x86-64-v2
- mtune : ivybridge
- rust_host_platform : "i686-unknown-linux-gnu"

flags:

Expand Down
1 change: 1 addition & 0 deletions data/macros/arch/x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ definitions:
- cpp : "%(compiler_cpp) -m32"
- march : x86-64-v2
- mtune : ivybridge
- rust_host_platform : "i686-unknown-linux-gnu"

flags:

Expand Down
3 changes: 2 additions & 1 deletion data/macros/arch/x86_64-stage1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -26,4 +27,4 @@ flags:

defaultTuningGroups :
- base
- optimize
- optimize
1 change: 1 addition & 0 deletions data/macros/arch/x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ definitions:
- cpp : "%(compiler_cpp)"
- march : x86-64-v2
- mtune : ivybridge
- rust_host_platform : "x86_64-unknown-linux-gnu"

flags:

Expand Down
6 changes: 6 additions & 0 deletions source/drafter/build/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +78,11 @@ public enum BuildType : string
*/
PythonSetuptools = "PythonSetuptools",

/**
* Uses cargo.
*/
Cargo = "cargo",

/**
* Unsupported tooling
*/
Expand Down
60 changes: 60 additions & 0 deletions source/drafter/build/rust.d
Original file line number Diff line number Diff line change
@@ -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";
}
}
1 change: 1 addition & 0 deletions source/drafter/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion source/drafter/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down