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
|
/// Get various configuration information needed
|
||||||
/// to compile programs which use Wasmer
|
/// to compile programs which use Wasmer
|
||||||
|
#[clap(subcommand)]
|
||||||
Config(Config),
|
Config(Config),
|
||||||
|
|
||||||
/// Update wasmer to the latest version
|
/// Update wasmer to the latest version
|
||||||
|
|||||||
@@ -3,38 +3,52 @@ use anyhow::{Context, Result};
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use wasmer_registry::PartialWapmConfig;
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
/// The options for the `wasmer config` subcommand
|
/// The options for the `wasmer config` subcommand: `wasmer config get prefix`
|
||||||
pub struct Config {
|
pub enum Config {
|
||||||
/// Print the installation prefix.
|
/// Get a value from the current wasmer config
|
||||||
#[clap(long, conflicts_with = "pkg-config")]
|
#[clap(subcommand)]
|
||||||
prefix: bool,
|
Get(RetrievableConfigField),
|
||||||
|
/// Set a value in the current wasmer config
|
||||||
|
#[clap(subcommand)]
|
||||||
|
Set(StorableConfigField),
|
||||||
|
}
|
||||||
|
|
||||||
/// Directory containing Wasmer executables.
|
/// Value that can be queried from the wasmer config
|
||||||
#[clap(long, conflicts_with = "pkg-config")]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, clap::Subcommand)]
|
||||||
bindir: bool,
|
pub enum RetrievableConfigField {
|
||||||
|
/// `prefix`
|
||||||
|
Prefix,
|
||||||
|
/// `bin-dir`
|
||||||
|
Bindir,
|
||||||
|
/// `includedir`
|
||||||
|
Includedir,
|
||||||
|
/// `libdir`
|
||||||
|
Libdir,
|
||||||
|
/// `libs`
|
||||||
|
Libs,
|
||||||
|
/// `cflags`
|
||||||
|
Cflags,
|
||||||
|
/// `pkg-config`
|
||||||
|
PkgConfig,
|
||||||
|
}
|
||||||
|
|
||||||
/// Directory containing Wasmer headers.
|
/// Setting that can be stored in the wasmer config
|
||||||
#[clap(long, conflicts_with = "pkg-config")]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, clap::Subcommand)]
|
||||||
includedir: bool,
|
pub enum StorableConfigField {
|
||||||
|
/// `registry.url`
|
||||||
|
#[clap(name = "registry.url")]
|
||||||
|
RegistryUrl(SetRegistryUrl),
|
||||||
|
}
|
||||||
|
|
||||||
/// Directory containing Wasmer libraries.
|
/// Set a new registry URL
|
||||||
#[clap(long, conflicts_with = "pkg-config")]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)]
|
||||||
libdir: bool,
|
pub struct SetRegistryUrl {
|
||||||
|
/// Url of the registry
|
||||||
/// Libraries needed to link against Wasmer components.
|
#[clap(name = "URL")]
|
||||||
#[clap(long, conflicts_with = "pkg-config")]
|
pub url: String,
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@@ -44,6 +58,8 @@ impl Config {
|
|||||||
.context("failed to retrieve the wasmer config".to_string())
|
.context("failed to retrieve the wasmer config".to_string())
|
||||||
}
|
}
|
||||||
fn inner_execute(&self) -> Result<()> {
|
fn inner_execute(&self) -> Result<()> {
|
||||||
|
use self::Config::{Get, Set};
|
||||||
|
|
||||||
let key = "WASMER_DIR";
|
let key = "WASMER_DIR";
|
||||||
let wasmer_dir = env::var(key)
|
let wasmer_dir = env::var(key)
|
||||||
.or_else(|e| {
|
.or_else(|e| {
|
||||||
@@ -65,37 +81,55 @@ impl Config {
|
|||||||
let cflags = format!("-I{}", includedir);
|
let cflags = format!("-I{}", includedir);
|
||||||
let libs = format!("-L{} -lwasmer", libdir);
|
let libs = format!("-L{} -lwasmer", libdir);
|
||||||
|
|
||||||
if self.pkg_config {
|
match self {
|
||||||
println!("prefix={}", prefixdir);
|
Get(g) => match g {
|
||||||
println!("exec_prefix={}", bindir);
|
RetrievableConfigField::PkgConfig => {
|
||||||
println!("includedir={}", includedir);
|
println!("prefix={}", prefixdir);
|
||||||
println!("libdir={}", libdir);
|
println!("exec_prefix={}", bindir);
|
||||||
println!();
|
println!("includedir={}", includedir);
|
||||||
println!("Name: wasmer");
|
println!("libdir={}", libdir);
|
||||||
println!("Description: The Wasmer library for running WebAssembly");
|
println!();
|
||||||
println!("Version: {}", VERSION);
|
println!("Name: wasmer");
|
||||||
println!("Cflags: {}", cflags);
|
println!("Description: The Wasmer library for running WebAssembly");
|
||||||
println!("Libs: {}", libs);
|
println!("Version: {}", VERSION);
|
||||||
return Ok(());
|
println!("Cflags: {}", cflags);
|
||||||
}
|
println!("Libs: {}", libs);
|
||||||
|
}
|
||||||
if self.prefix {
|
RetrievableConfigField::Prefix => {
|
||||||
println!("{}", prefixdir);
|
println!("{}", prefixdir);
|
||||||
}
|
}
|
||||||
if self.bindir {
|
RetrievableConfigField::Bindir => {
|
||||||
println!("{}", bindir);
|
println!("{}", bindir);
|
||||||
}
|
}
|
||||||
if self.includedir {
|
RetrievableConfigField::Includedir => {
|
||||||
println!("{}", includedir);
|
println!("{}", includedir);
|
||||||
}
|
}
|
||||||
if self.libdir {
|
RetrievableConfigField::Libdir => {
|
||||||
println!("{}", libdir);
|
println!("{}", libdir);
|
||||||
}
|
}
|
||||||
if self.libs {
|
RetrievableConfigField::Libs => {
|
||||||
println!("{}", libs);
|
println!("{}", libs);
|
||||||
}
|
}
|
||||||
if self.cflags {
|
RetrievableConfigField::Cflags => {
|
||||||
println!("{}", 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user