Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify dependencies to Linera binaries #1107

Merged
merged 7 commits into from
Oct 10, 2023
Merged
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion linera-explorer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "linera <linera@contact.com>",
"name": "linera-explorer",
"version": "0.4.0",
"version": "0.4.1",
"scripts": {
"clean": "rm -rf pkg dist package-lock.json gql",
"wipe": "npm run clean && rm -rf node_modules",
Expand Down
2 changes: 1 addition & 1 deletion linera-indexer/example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "linera-indexer-example"
version = "0.4.0"
version = "0.4.1"
description = "Indexer example."
authors = ["Linera <contact@linera.io>"]
readme = "README.md"
Expand Down
7 changes: 5 additions & 2 deletions linera-indexer/example/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use linera_indexer_graphql_client::{
indexer::{plugins, state, Plugins, State},
operations::{get_operation, GetOperation, OperationKey},
};
use linera_service::cli_wrappers::{resolve_binary, Database, LocalNetwork, Network};
use linera_service::{
cli_wrappers::{Database, LocalNetwork, Network},
util::resolve_binary,
};
use linera_service_graphql_client::{block, request, transfer, Block, Transfer};
use once_cell::sync::Lazy;
use std::{rc::Rc, str::FromStr, time::Duration};
Expand All @@ -24,7 +27,7 @@ static INTEGRATION_TEST_GUARD: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));

async fn run_indexer(tmp_dir: &Rc<TempDir>) -> Child {
let port = 8081;
let path = resolve_binary("linera-indexer", Some("linera-indexer-example"))
let path = resolve_binary("linera-indexer", "linera-indexer-example")
.await
.unwrap();
let mut command = Command::new(path);
Expand Down
2 changes: 1 addition & 1 deletion linera-indexer/graphql-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "linera-indexer-graphql-client"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
description = "GraphQL client for the indexer"
readme = "README.md"
Expand Down
6 changes: 3 additions & 3 deletions linera-indexer/graphql-client/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use linera_service::cli_wrappers::resolve_binary;
use linera_service::util::resolve_binary;
use std::{io::Read, rc::Rc};
use tempfile::tempdir;
use tokio::process::Command;

#[test_log::test(tokio::test)]
async fn test_check_indexer_schema() {
let tmp_dir = Rc::new(tempdir().unwrap());
let path = resolve_binary("linera-indexer", Some("linera-indexer-example"))
let path = resolve_binary("linera-indexer", "linera-indexer-example")
.await
.unwrap();
let mut command = Command::new(path);
Expand All @@ -33,7 +33,7 @@ async fn test_check_indexer_schema() {
#[test_log::test(tokio::test)]
async fn test_check_indexer_operations_schema() {
let tmp_dir = Rc::new(tempdir().unwrap());
let path = resolve_binary("linera-indexer", Some("linera-indexer-example"))
let path = resolve_binary("linera-indexer", "linera-indexer-example")
.await
.unwrap();
let mut command = Command::new(path);
Expand Down
2 changes: 1 addition & 1 deletion linera-indexer/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "linera-indexer"
version = "0.4.0"
version = "0.4.1"
description = "Indexer for Linera protocol."
authors = ["Linera <contact@linera.io>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion linera-indexer/plugins/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "linera-indexer-plugins"
version = "0.4.0"
version = "0.4.1"
description = "Indexer plugins."
authors = ["Linera <contact@linera.io>"]
readme = "README.md"
Expand Down
10 changes: 8 additions & 2 deletions linera-service-graphql-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ homepage = "https://linera.dev"
documentation = "https://docs.rs/linera-service-graphql-client/latest/linera_service_graphql_client/"
license = "Apache-2.0"

[features]
default = ["rocksdb"]
rocksdb = ["linera-service/rocksdb"]
aws = ["linera-service/aws"]
scylladb = ["linera-service/scylladb"]

[dependencies]
graphql_client = { version = "0.13", features = [ "reqwest" ] }
linera-base = { workspace = true }
Expand All @@ -24,10 +30,10 @@ linera-execution = { workspace = true }

[dev-dependencies]
fungible = { workspace = true }
linera-service = { workspace = true }
linera-service = { workspace = true, features = ["test"] }
once_cell = { workspace = true }
test-log = { workspace = true, features = ["trace"] }
tempfile = {workspace = true }
tokio = { workspace = true, features = ["full", "test-util"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["fmt"] }
tracing-subscriber = { workspace = true, features = ["fmt"] }
20 changes: 10 additions & 10 deletions linera-service-graphql-client/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

#![cfg(any(feature = "rocksdb", feature = "aws", feature = "scylladb"))]

use linera_service::cli_wrappers::resolve_binary;
use once_cell::sync::Lazy;
use std::{io::Read, rc::Rc};
use tempfile::tempdir;
use tokio::{process::Command, sync::Mutex};

use fungible::{FungibleTokenAbi, InitialState};
use linera_base::{data_types::Amount, identifiers::ChainId};
use linera_service::cli_wrappers::{Database, LocalNetwork, Network};
use linera_service::{
cli_wrappers::{Database, LocalNetwork, Network},
util::resolve_binary,
};
use linera_service_graphql_client::{
applications, block, blocks, chains, request, transfer, Applications, Block, Blocks, Chains,
Transfer,
};
use std::{collections::BTreeMap, str::FromStr};
use once_cell::sync::Lazy;
use std::{collections::BTreeMap, io::Read, rc::Rc, str::FromStr};
use tempfile::tempdir;
use tokio::{process::Command, sync::Mutex};

/// A static lock to prevent integration tests from running in parallel.
pub static INTEGRATION_TEST_GUARD: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
Expand Down Expand Up @@ -54,7 +54,7 @@ async fn run_end_to_end_queries(database: Database) {
let _guard = INTEGRATION_TEST_GUARD.lock().await;
let network = Network::Grpc;
let mut local_net = LocalNetwork::new_for_testing(database, network).unwrap();
let mut client = local_net.make_client(network);
let client = local_net.make_client(network);
local_net.generate_initial_validator_config().await.unwrap();

client.create_genesis_config().await.unwrap();
Expand Down Expand Up @@ -141,7 +141,7 @@ async fn run_end_to_end_queries(database: Database) {
#[test_log::test(tokio::test)]
async fn test_check_service_schema() {
let tmp_dir = Rc::new(tempdir().unwrap());
let path = resolve_binary("linera-schema-export", Some("linera-service"))
let path = resolve_binary("linera-schema-export", "linera-service")
.await
.unwrap();
let mut command = Command::new(path);
Expand Down
122 changes: 6 additions & 116 deletions linera-service/src/cli_wrappers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::config::WalletState;
use crate::{config::WalletState, util};
use anyhow::{Context, Result};
use async_graphql::InputType;
use linera_base::{
Expand All @@ -11,7 +11,6 @@ use linera_base::{
identifiers::{ChainId, MessageId, Owner},
};
use linera_execution::Bytecode;
use once_cell::sync::OnceCell;
use serde::ser::Serialize;
use serde_json::{json, value::Value};
use std::{
Expand All @@ -25,10 +24,7 @@ use std::{
time::Duration,
};
use tempfile::{tempdir, TempDir};
use tokio::{
process::{Child, Command},
sync::Mutex,
};
use tokio::process::{Child, Command};
use tonic_health::proto::{
health_check_response::ServingStatus, health_client::HealthClient, HealthCheckRequest,
};
Expand All @@ -37,17 +33,13 @@ use tracing::{info, warn};
#[cfg(any(test, feature = "test"))]
use linera_views::common::get_table_name;

/// The name of the environment variable that allows specifying additional arguments to be passed
/// to `cargo` when starting client, server and proxy processes.
pub const CARGO_ENV: &str = "LOCAL_NET_CARGO_PARAMS";

/// The name of the environment variable that allows specifying additional arguments to be passed
/// to the binary when starting a server.
const SERVER_ENV: &str = "LOCAL_NET_SERVER_PARAMS";
const SERVER_ENV: &str = "LINERA_SERVER_PARAMS";

/// The name of the environment variable that allows specifying additional arguments to be passed
/// to the node-service command of the client.
const CLIENT_SERVICE_ENV: &str = "LOCAL_NET_CLIENT_SERVICE_PARAMS";
const CLIENT_SERVICE_ENV: &str = "LINERA_CLIENT_SERVICE_PARAMS";

#[derive(Copy, Clone)]
pub enum Network {
Expand Down Expand Up @@ -170,7 +162,7 @@ impl ClientWrapper {
}

async fn run(&self) -> Result<Command> {
let path = resolve_binary("linera", None).await?;
let path = util::resolve_binary("linera", env!("CARGO_PKG_NAME")).await?;
let mut command = Command::new(path);
command
.current_dir(&self.tmp_dir.path().canonicalize()?)
Expand Down Expand Up @@ -626,7 +618,7 @@ impl LocalNetwork {
}

async fn command_for_binary(&self, name: &'static str) -> Result<Command> {
let path = resolve_binary(name, None).await?;
let path = util::resolve_binary(name, env!("CARGO_PKG_NAME")).await?;
let mut command = Command::new(path);
command
.current_dir(&self.tmp_dir.path().canonicalize()?)
Expand Down Expand Up @@ -1065,105 +1057,3 @@ impl NodeService {
serde_json::from_value(data["requestApplication"].clone()).unwrap()
}
}

#[allow(unused_mut)]
fn detect_current_features() -> Vec<&'static str> {
let mut features = vec![];
#[cfg(feature = "benchmark")]
{
features.push("benchmark");
}
#[cfg(feature = "wasmer")]
{
features.push("wasmer");
}
#[cfg(feature = "wasmtime")]
{
features.push("wasmtime");
}
#[cfg(feature = "rocksdb")]
{
features.push("rocksdb");
}
#[cfg(feature = "scylladb")]
{
features.push("scylladb");
}
#[cfg(feature = "aws")]
{
features.push("aws");
}
features
}

async fn cargo_force_build_binary(name: &'static str, package: Option<&'static str>) -> PathBuf {
let package = package.unwrap_or(env!("CARGO_PKG_NAME"));
let mut build_command = Command::new("cargo");
build_command.args(["build", "-p", package]);
let is_release = if let Ok(var) = env::var(CARGO_ENV) {
let extra_args = var.split_whitespace();
build_command.args(extra_args.clone());
let extra_args: HashSet<_> = extra_args.into_iter().map(str::trim).collect();
extra_args.contains("-r") || extra_args.contains("--release")
} else {
false
};
// Use the same features as the current environment so that we don't rebuild as often.
let features = detect_current_features().join(",");
build_command
.arg("--no-default-features")
.arg("--features")
.arg(features);
build_command.args(["--bin", name]);
info!("Running compiler: {:?}", build_command);
assert!(build_command
.spawn()
.unwrap()
.wait()
.await
.unwrap()
.success());
let mut cargo_locate_command = Command::new("cargo");
cargo_locate_command.args(["locate-project", "--workspace", "--message-format", "plain"]);
let output = cargo_locate_command.output().await.unwrap().stdout;
let workspace_path = Path::new(std::str::from_utf8(&output).unwrap().trim())
.parent()
.unwrap();
if is_release {
workspace_path
.join("target/release")
.join(name)
.canonicalize()
.unwrap()
} else {
workspace_path
.join("target/debug")
.join(name)
.canonicalize()
.unwrap()
}
}

#[cfg(debug_assertions)]
pub async fn resolve_binary(name: &'static str, package: Option<&'static str>) -> Result<PathBuf> {
Ok(cargo_build_binary(name, package).await)
}

#[cfg(not(debug_assertions))]
pub async fn resolve_binary(name: &'static str, _package: Option<&'static str>) -> Result<PathBuf> {
crate::util::resolve_cargo_binary(name)
}

pub async fn cargo_build_binary(name: &'static str, package: Option<&'static str>) -> PathBuf {
type Key = (&'static str, Option<&'static str>);
static COMPILED_BINARIES: OnceCell<Mutex<HashMap<Key, PathBuf>>> = OnceCell::new();
let mut binaries = COMPILED_BINARIES.get_or_init(Default::default).lock().await;
match binaries.get(&(name, package)) {
Some(path) => path.clone(),
None => {
let path = cargo_force_build_binary(name, package).await;
binaries.insert((name, package), path.clone());
path
}
}
}
4 changes: 2 additions & 2 deletions linera-service/src/linera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ fn deserialize_response(response: RpcMessage) -> Option<ChainInfoResponse> {

#[derive(StructOpt)]
#[structopt(
name = "Linera Client",
name = "Linera client tool",
about = "A Byzantine-fault tolerant sidechain with low-latency finality and high throughput"
)]
struct ClientOptions {
Expand Down Expand Up @@ -1796,7 +1796,7 @@ async fn main() -> Result<(), anyhow::Error> {
ProjectCommand::Test { path } => {
let path = path.clone().unwrap_or_else(|| env::current_dir().unwrap());
let project = Project::from_existing_project(path)?;
Ok(project.test()?)
Ok(project.test().await?)
}
ProjectCommand::PublishAndCreate { .. } => options.run_command_with_storage().await,
},
Expand Down
Loading