mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 12:48:20 +00:00
Initial implementation for new wasmer config
This commit is contained in:
@@ -126,6 +126,7 @@ enum WasmerCLIOptions {
|
||||
|
||||
/// Get various configuration information needed
|
||||
/// to compile programs which use Wasmer
|
||||
#[clap(subcommand)]
|
||||
Config(Config),
|
||||
|
||||
/// Update wasmer to the latest version
|
||||
|
||||
@@ -3,38 +3,52 @@ use anyhow::{Context, Result};
|
||||
use clap::Parser;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use wasmer_registry::PartialWapmConfig;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
/// The options for the `wasmer config` subcommand
|
||||
pub struct Config {
|
||||
/// Print the installation prefix.
|
||||
#[clap(long, conflicts_with = "pkg-config")]
|
||||
prefix: bool,
|
||||
/// The options for the `wasmer config` subcommand: `wasmer config get prefix`
|
||||
pub enum Config {
|
||||
/// Get a value from the current wasmer config
|
||||
#[clap(subcommand)]
|
||||
Get(RetrievableConfigField),
|
||||
/// Set a value in the current wasmer config
|
||||
#[clap(subcommand)]
|
||||
Set(StorableConfigField),
|
||||
}
|
||||
|
||||
/// Directory containing Wasmer executables.
|
||||
#[clap(long, conflicts_with = "pkg-config")]
|
||||
bindir: bool,
|
||||
/// Value that can be queried from the wasmer config
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, clap::Subcommand)]
|
||||
pub enum RetrievableConfigField {
|
||||
/// `prefix`
|
||||
Prefix,
|
||||
/// `bin-dir`
|
||||
Bindir,
|
||||
/// `includedir`
|
||||
Includedir,
|
||||
/// `libdir`
|
||||
Libdir,
|
||||
/// `libs`
|
||||
Libs,
|
||||
/// `cflags`
|
||||
Cflags,
|
||||
/// `pkg-config`
|
||||
PkgConfig,
|
||||
}
|
||||
|
||||
/// Directory containing Wasmer headers.
|
||||
#[clap(long, conflicts_with = "pkg-config")]
|
||||
includedir: bool,
|
||||
/// Setting that can be stored in the wasmer config
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, clap::Subcommand)]
|
||||
pub enum StorableConfigField {
|
||||
/// `registry.url`
|
||||
#[clap(name = "registry.url")]
|
||||
RegistryUrl(SetRegistryUrl),
|
||||
}
|
||||
|
||||
/// Directory containing Wasmer libraries.
|
||||
#[clap(long, conflicts_with = "pkg-config")]
|
||||
libdir: bool,
|
||||
|
||||
/// Libraries needed to link against Wasmer components.
|
||||
#[clap(long, conflicts_with = "pkg-config")]
|
||||
libs: bool,
|
||||
|
||||
/// C compiler flags for files that include Wasmer headers.
|
||||
#[clap(long, conflicts_with = "pkg-config")]
|
||||
cflags: bool,
|
||||
|
||||
/// It outputs the necessary details for compiling
|
||||
/// and linking a program to Wasmer, using the `pkg-config` format.
|
||||
#[clap(long)]
|
||||
pkg_config: bool,
|
||||
/// Set a new registry URL
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)]
|
||||
pub struct SetRegistryUrl {
|
||||
/// Url of the registry
|
||||
#[clap(name = "URL")]
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -44,6 +58,8 @@ impl Config {
|
||||
.context("failed to retrieve the wasmer config".to_string())
|
||||
}
|
||||
fn inner_execute(&self) -> Result<()> {
|
||||
use self::Config::{Get, Set};
|
||||
|
||||
let key = "WASMER_DIR";
|
||||
let wasmer_dir = env::var(key)
|
||||
.or_else(|e| {
|
||||
@@ -65,37 +81,55 @@ impl Config {
|
||||
let cflags = format!("-I{}", includedir);
|
||||
let libs = format!("-L{} -lwasmer", libdir);
|
||||
|
||||
if self.pkg_config {
|
||||
println!("prefix={}", prefixdir);
|
||||
println!("exec_prefix={}", bindir);
|
||||
println!("includedir={}", includedir);
|
||||
println!("libdir={}", libdir);
|
||||
println!();
|
||||
println!("Name: wasmer");
|
||||
println!("Description: The Wasmer library for running WebAssembly");
|
||||
println!("Version: {}", VERSION);
|
||||
println!("Cflags: {}", cflags);
|
||||
println!("Libs: {}", libs);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.prefix {
|
||||
println!("{}", prefixdir);
|
||||
}
|
||||
if self.bindir {
|
||||
println!("{}", bindir);
|
||||
}
|
||||
if self.includedir {
|
||||
println!("{}", includedir);
|
||||
}
|
||||
if self.libdir {
|
||||
println!("{}", libdir);
|
||||
}
|
||||
if self.libs {
|
||||
println!("{}", libs);
|
||||
}
|
||||
if self.cflags {
|
||||
println!("{}", cflags);
|
||||
match self {
|
||||
Get(g) => match g {
|
||||
RetrievableConfigField::PkgConfig => {
|
||||
println!("prefix={}", prefixdir);
|
||||
println!("exec_prefix={}", bindir);
|
||||
println!("includedir={}", includedir);
|
||||
println!("libdir={}", libdir);
|
||||
println!();
|
||||
println!("Name: wasmer");
|
||||
println!("Description: The Wasmer library for running WebAssembly");
|
||||
println!("Version: {}", VERSION);
|
||||
println!("Cflags: {}", cflags);
|
||||
println!("Libs: {}", libs);
|
||||
}
|
||||
RetrievableConfigField::Prefix => {
|
||||
println!("{}", prefixdir);
|
||||
}
|
||||
RetrievableConfigField::Bindir => {
|
||||
println!("{}", bindir);
|
||||
}
|
||||
RetrievableConfigField::Includedir => {
|
||||
println!("{}", includedir);
|
||||
}
|
||||
RetrievableConfigField::Libdir => {
|
||||
println!("{}", libdir);
|
||||
}
|
||||
RetrievableConfigField::Libs => {
|
||||
println!("{}", libs);
|
||||
}
|
||||
RetrievableConfigField::Cflags => {
|
||||
println!("{}", cflags);
|
||||
}
|
||||
},
|
||||
Set(s) => match s {
|
||||
StorableConfigField::RegistryUrl(s) => {
|
||||
let config_file = PartialWapmConfig::get_file_location()
|
||||
.map_err(|e| anyhow::anyhow!("could not find config file {e}"))?;
|
||||
let mut config = PartialWapmConfig::from_file()
|
||||
.map_err(|e| anyhow::anyhow!("could not find config file {e}"))?;
|
||||
config.registry.set_current_registry(&s.url);
|
||||
config
|
||||
.save(config_file)
|
||||
.with_context(|| anyhow::anyhow!("could not save config file"))?;
|
||||
println!(
|
||||
"set current registry to {}",
|
||||
config.registry.get_current_registry()
|
||||
);
|
||||
}
|
||||
},
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user