mirror of
https://github.com/faas-rs/faasd-in-rust.git
synced 2025-06-08 15:56:48 +00:00
hakari to speedup building, change structure of
the workspace
This commit is contained in:
parent
d98cfd6289
commit
9e0955e530
27
.config/hakari.toml
Normal file
27
.config/hakari.toml
Normal file
@ -0,0 +1,27 @@
|
||||
# This file contains settings for `cargo hakari`.
|
||||
# See https://docs.rs/cargo-hakari/latest/cargo_hakari/config for a full list of options.
|
||||
|
||||
hakari-package = "my-workspace-hack"
|
||||
|
||||
# Format version for hakari's output. Version 4 requires cargo-hakari 0.9.22 or above.
|
||||
dep-format-version = "4"
|
||||
|
||||
# Setting workspace.resolver = "2" or higher in the root Cargo.toml is HIGHLY recommended.
|
||||
# Hakari works much better with the v2 resolver. (The v2 and v3 resolvers are identical from
|
||||
# hakari's perspective, so you're welcome to set either.)
|
||||
#
|
||||
# For more about the new feature resolver, see:
|
||||
# https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver
|
||||
resolver = "2"
|
||||
|
||||
# Add triples corresponding to platforms commonly used by developers here.
|
||||
# https://doc.rust-lang.org/rustc/platform-support.html
|
||||
platforms = [
|
||||
"x86_64-unknown-linux-gnu",
|
||||
# "x86_64-apple-darwin",
|
||||
# "aarch64-apple-darwin",
|
||||
# "x86_64-pc-windows-msvc",
|
||||
]
|
||||
|
||||
# Write out exact versions rather than a semver range. (Defaults to false.)
|
||||
# exact-versions = true
|
21
Cargo.lock
generated
21
Cargo.lock
generated
@ -583,6 +583,7 @@ name = "faas-rs"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"actix-web",
|
||||
"my-workspace-hack",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"service",
|
||||
@ -1172,6 +1173,25 @@ version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03"
|
||||
|
||||
[[package]]
|
||||
name = "my-workspace-hack"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"actix-router",
|
||||
"bytes",
|
||||
"log",
|
||||
"memchr",
|
||||
"mio",
|
||||
"prost",
|
||||
"regex",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
"serde",
|
||||
"syn",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.1.0"
|
||||
@ -1548,6 +1568,7 @@ dependencies = [
|
||||
"containerd-client",
|
||||
"env_logger",
|
||||
"log",
|
||||
"my-workspace-hack",
|
||||
"prost-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -1,7 +1,14 @@
|
||||
[workspace]
|
||||
members = ["app", "service"]
|
||||
members = ["crates/*"]
|
||||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.0.1"
|
||||
authors = ["sparkzky", "Samuka007"]
|
||||
|
||||
[workspace.metadata.crane]
|
||||
name = "faas-rs"
|
||||
|
||||
# API 模块:基于 Actix Web 提供 RESTful 接口,调用 service 模块的功能。
|
||||
# 测试:编写单元测试和集成测试,确保服务的可靠性。
|
||||
# 镜像管理:实现缓存逻辑,并支持镜像解包和检查功能
|
||||
|
@ -8,4 +8,5 @@ actix-web = "4.0"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
service = { path = "../service" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
serde_json = "1.0"
|
||||
my-workspace-hack = { version = "0.1", path = "../my-workspace-hack" }
|
4
crates/my-workspace-hack/.gitattributes
vendored
Normal file
4
crates/my-workspace-hack/.gitattributes
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# Avoid putting conflict markers in the generated Cargo.toml file, since their presence breaks
|
||||
# Cargo.
|
||||
# Also do not check out the file as CRLF on Windows, as that's what hakari needs.
|
||||
Cargo.toml merge=binary -crlf
|
45
crates/my-workspace-hack/Cargo.toml
Normal file
45
crates/my-workspace-hack/Cargo.toml
Normal file
@ -0,0 +1,45 @@
|
||||
# This file is generated by `cargo hakari`.
|
||||
# To regenerate, run:
|
||||
# cargo hakari generate
|
||||
|
||||
[package]
|
||||
name = "my-workspace-hack"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
description = "workspace-hack package, managed by hakari"
|
||||
# You can choose to publish this crate: see https://docs.rs/cargo-hakari/latest/cargo_hakari/publishing.
|
||||
publish = false
|
||||
|
||||
# The parts of the file between the BEGIN HAKARI SECTION and END HAKARI SECTION comments
|
||||
# are managed by hakari.
|
||||
|
||||
### BEGIN HAKARI SECTION
|
||||
[dependencies]
|
||||
actix-router = { version = "0.5", default-features = false, features = ["http", "unicode"] }
|
||||
bytes = { version = "1" }
|
||||
log = { version = "0.4", default-features = false, features = ["std"] }
|
||||
memchr = { version = "2" }
|
||||
mio = { version = "1", features = ["net", "os-ext"] }
|
||||
prost = { version = "0.13", features = ["prost-derive"] }
|
||||
regex = { version = "1" }
|
||||
regex-automata = { version = "0.4", default-features = false, features = ["dfa-onepass", "hybrid", "meta", "nfa-backtrack", "perf-inline", "perf-literal", "unicode"] }
|
||||
regex-syntax = { version = "0.8" }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
tracing = { version = "0.1", features = ["log"] }
|
||||
tracing-core = { version = "0.1", default-features = false, features = ["std"] }
|
||||
|
||||
[build-dependencies]
|
||||
actix-router = { version = "0.5", default-features = false, features = ["http", "unicode"] }
|
||||
bytes = { version = "1" }
|
||||
log = { version = "0.4", default-features = false, features = ["std"] }
|
||||
memchr = { version = "2" }
|
||||
prost = { version = "0.13", features = ["prost-derive"] }
|
||||
regex = { version = "1" }
|
||||
regex-automata = { version = "0.4", default-features = false, features = ["dfa-onepass", "hybrid", "meta", "nfa-backtrack", "perf-inline", "perf-literal", "unicode"] }
|
||||
regex-syntax = { version = "0.8" }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
syn = { version = "2", features = ["extra-traits", "fold", "full", "visit", "visit-mut"] }
|
||||
tracing = { version = "0.1", features = ["log"] }
|
||||
tracing-core = { version = "0.1", default-features = false, features = ["std"] }
|
||||
|
||||
### END HAKARI SECTION
|
2
crates/my-workspace-hack/build.rs
Normal file
2
crates/my-workspace-hack/build.rs
Normal file
@ -0,0 +1,2 @@
|
||||
// A build script is required for cargo to consider build dependencies.
|
||||
fn main() {}
|
1
crates/my-workspace-hack/src/lib.rs
Normal file
1
crates/my-workspace-hack/src/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
// This is a stub lib.rs.
|
@ -11,4 +11,5 @@ serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
log = "0.4"
|
||||
env_logger = "0.10"
|
||||
prost-types = "0.13.4"
|
||||
prost-types = "0.13.4"
|
||||
my-workspace-hack = { version = "0.1", path = "../my-workspace-hack" }
|
@ -1,15 +1,14 @@
|
||||
use containerd_client::{
|
||||
services::v1::{
|
||||
container::Runtime, Container, CreateContainerRequest, CreateTaskRequest,
|
||||
DeleteContainerRequest, DeleteTaskRequest, GetImageRequest, KillRequest,
|
||||
DeleteContainerRequest, DeleteTaskRequest, KillRequest,
|
||||
ListContainersRequest, ListTasksRequest, StartRequest, WaitRequest,
|
||||
},
|
||||
tonic::Request,
|
||||
with_namespace, Client,
|
||||
};
|
||||
use prost_types::Any;
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs::{self, File},
|
||||
sync::{Arc, Mutex},
|
||||
time::Duration,
|
||||
@ -17,7 +16,8 @@ use std::{
|
||||
use tokio::time::timeout;
|
||||
|
||||
// config.json,dockerhub密钥
|
||||
const DOCKER_CONFIG_DIR: &str = "/var/lib/faasd/.docker/";
|
||||
// const DOCKER_CONFIG_DIR: &str = "/var/lib/faasd/.docker/";
|
||||
|
||||
// 命名空间(容器的)
|
||||
const NAMESPACE: &str = "default";
|
||||
|
||||
@ -36,7 +36,7 @@ impl Service {
|
||||
}
|
||||
|
||||
pub async fn create_container(&self, image: String, cid: String) {
|
||||
// let spec = include_str!("../../container_spec.json").to_string();
|
||||
// let spec = include_str!("../container_spec.json").to_string();
|
||||
// let spec = Any {
|
||||
// type_url: "types.containerd.io/opencontainers/runtime-spec/1/Spec".to_string(),
|
||||
// value: spec.into_bytes(),
|
68
flake.nix
68
flake.nix
@ -53,24 +53,82 @@
|
||||
fileset = lib.fileset.unions [
|
||||
./Cargo.toml
|
||||
./Cargo.lock
|
||||
(craneLib.fileset.commonCargoSources ./app)
|
||||
(craneLib.fileset.commonCargoSources ./service)
|
||||
(craneLib.fileset.commonCargoSources ./crates/app)
|
||||
(craneLib.fileset.commonCargoSources ./crates/service)
|
||||
(craneLib.fileset.commonCargoSources ./crates/my-workspace-hack)
|
||||
(craneLib.fileset.commonCargoSources crate)
|
||||
];
|
||||
};
|
||||
|
||||
faas-rs-crate = craneLib.buildPackage ( individualCrateArgs // {
|
||||
pname = "faas-rs";
|
||||
cargoExtraArgs = "--bin faas-rs";
|
||||
src = fileSetForCrate ./app;
|
||||
cargoExtraArgs = "-p faas-rs";
|
||||
src = fileSetForCrate ./crates/app;
|
||||
});
|
||||
in
|
||||
with pkgs;
|
||||
{
|
||||
checks = { inherit faas-rs-crate; };
|
||||
checks = {
|
||||
inherit faas-rs-crate;
|
||||
|
||||
# Run clippy (and deny all warnings) on the workspace source,
|
||||
# again, reusing the dependency artifacts from above.
|
||||
#
|
||||
# Note that this is done as a separate derivation so that
|
||||
# we can block the CI if there are issues here, but not
|
||||
# prevent downstream consumers from building our crate by itself.
|
||||
clippy = craneLib.cargoClippy (commonArgs // {
|
||||
inherit cargoArtifacts;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings -Z unstable-options";
|
||||
});
|
||||
|
||||
doc = craneLib.cargoDoc (commonArgs // {
|
||||
inherit cargoArtifacts;
|
||||
});
|
||||
|
||||
# Check formatting
|
||||
fmt = craneLib.cargoFmt {
|
||||
inherit src;
|
||||
};
|
||||
|
||||
# Run tests with cargo-nextest
|
||||
# Consider setting `doCheck = false` on other crate derivations
|
||||
# if you do not want the tests to run twice
|
||||
nextest = craneLib.cargoNextest (commonArgs // {
|
||||
inherit cargoArtifacts;
|
||||
partitions = 1;
|
||||
partitionType = "count";
|
||||
cargoNextestPartitionsExtraArgs = "--no-tests=pass";
|
||||
});
|
||||
|
||||
# Ensure that cargo-hakari is up to date
|
||||
hakari = craneLib.mkCargoDerivation {
|
||||
inherit src;
|
||||
pname = "my-workspace-hack";
|
||||
cargoArtifacts = null;
|
||||
doInstallCargoArtifacts = false;
|
||||
|
||||
buildPhaseCargoCommand = ''
|
||||
cargo hakari generate --diff # workspace-hack Cargo.toml is up-to-date
|
||||
cargo hakari manage-deps --dry-run # all workspace crates depend on workspace-hack
|
||||
cargo hakari verify
|
||||
'';
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkgs.cargo-hakari
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
packages.default = faas-rs-crate;
|
||||
|
||||
apps = {
|
||||
faas-rs = flake-utils.lib.mkApp {
|
||||
drv = faas-rs-crate;
|
||||
desc = "FaaS Rust Project";
|
||||
};
|
||||
};
|
||||
|
||||
devShells.default = craneLib.devShell {
|
||||
checks = self.checks.${system};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user