Skip to content

Commit

Permalink
add(smdk): default to wasi supported build arch (#3981)
Browse files Browse the repository at this point in the history
* add(smdk): default to wasi supported build arch

* chore(smdk): wasi ci misc
  • Loading branch information
digikata authored May 1, 2024
1 parent 00c01c5 commit 438aa15
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 113 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,6 @@ jobs:
- uses: actions/checkout@v4
- name: Install Rust Stable
uses: dtolnay/rust-toolchain@stable
- name: install wasm target
run: rustup target add wasm32-unknown-unknown
- name: Build Regex SmartModule
run: make -C smartmodule/regex-filter

Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-builder/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl PackageInfo {
Ok(path)
}

/// path to package's wasm32 target
/// path to package's wasm32-wasi target
pub fn target_wasm32_wasi_path(&self) -> anyhow::Result<PathBuf> {
let mut path = self.target_dir.clone();
path.push("wasm32-wasi");
Expand Down
14 changes: 7 additions & 7 deletions crates/smartmodule-development-kit/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cargo_builder::package::PackageInfo;
use cargo_builder::cargo::Cargo;

use crate::cmd::PackageCmd;
use crate::ENV_SMDK_WASI;
use crate::ENV_SMDK_NOWASI;

pub(crate) const BUILD_TARGET: &str = "wasm32-unknown-unknown";
pub(crate) const BUILD_TARGET_WASI: &str = "wasm32-wasi";
Expand All @@ -23,20 +23,20 @@ pub struct BuildCmd {
#[arg(raw = true)]
extra_arguments: Vec<String>,

/// Build wasi target
#[arg(long, env = ENV_SMDK_WASI)]
wasi: bool,
/// Build a non wasi target (only use if needed for backward compatiblity)
#[arg(long, env = ENV_SMDK_NOWASI, hide_short_help = true)]
nowasi: bool,
}

impl BuildCmd {
pub(crate) fn process(self) -> Result<()> {
let opt = self.package.as_opt();
let p = PackageInfo::from_options(&opt)?;

let build_target = if self.wasi {
BUILD_TARGET_WASI
} else {
let build_target = if self.nowasi {
BUILD_TARGET
} else {
BUILD_TARGET_WASI
};
let cargo = Cargo::build()
.profile(opt.release)
Expand Down
12 changes: 6 additions & 6 deletions crates/smartmodule-development-kit/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use fluvio_future::task::run_block_on;
use cargo_builder::package::PackageInfo;

use crate::cmd::PackageCmd;
use crate::ENV_SMDK_WASI;
use crate::ENV_SMDK_NOWASI;

pub const DEFAULT_META_LOCATION: &str = "SmartModule.toml";

Expand Down Expand Up @@ -40,8 +40,8 @@ pub struct LoadCmd {
dry_run: bool,

/// Build wasi target
#[arg(long, env = ENV_SMDK_WASI)]
wasi: bool,
#[arg(long, env = ENV_SMDK_NOWASI, hide_short_help = true)]
nowasi: bool,
}
impl LoadCmd {
pub(crate) fn process(self) -> Result<()> {
Expand Down Expand Up @@ -70,10 +70,10 @@ impl LoadCmd {
let raw_bytes = match &self.wasm_file {
Some(wasm_file) => crate::read_bytes_from_path(wasm_file)?,
None => {
let tgtpath = if self.wasi {
package_info.target_wasm32_wasi_path()?
} else {
let tgtpath = if self.nowasi {
package_info.target_wasm32_path()?
} else {
package_info.target_wasm32_wasi_path()?
};
crate::read_bytes_from_path(&tgtpath)?
}
Expand Down
2 changes: 1 addition & 1 deletion crates/smartmodule-development-kit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tracing::debug;

use cmd::SmdkCommand;

pub const ENV_SMDK_WASI: &str = "SMDK_WASI";
pub const ENV_SMDK_NOWASI: &str = "SMDK_NOWASI";

fn main() -> Result<()> {
fluvio_future::subscriber::init_tracer(None);
Expand Down
16 changes: 8 additions & 8 deletions crates/smartmodule-development-kit/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use hubutil::{
use tracing::debug;

use crate::cmd::PackageCmd;
use crate::ENV_SMDK_WASI;
use crate::ENV_SMDK_NOWASI;

pub const SMARTMODULE_TOML: &str = "SmartModule.toml";

Expand Down Expand Up @@ -45,8 +45,8 @@ pub struct PublishCmd {
#[arg(long, hide_short_help = true)]
remote: Option<String>,

#[arg(long, env=ENV_SMDK_WASI)]
wasi: bool,
#[arg(long, env=ENV_SMDK_NOWASI, hide_short_help = true)]
nowasi: bool,
}

impl PublishCmd {
Expand Down Expand Up @@ -101,7 +101,7 @@ impl PublishCmd {

Self::cleanup(&hubdir)?;

init_package_template(&package_info, self.wasi)?;
init_package_template(&package_info, self.nowasi)?;
check_package_meta_visiblity(&package_info)?;

Ok(hubdir)
Expand Down Expand Up @@ -170,7 +170,7 @@ pub fn package_push(opts: &PublishCmd, pkgpath: &str, access: &HubAccess) -> Res
Ok(())
}

pub fn init_package_template(package_info: &PackageInfo, wasi: bool) -> Result<()> {
pub fn init_package_template(package_info: &PackageInfo, nowasi: bool) -> Result<()> {
let sm_toml_path = find_smartmodule_toml(package_info)?;
let sm_metadata = SmartModuleMetadata::from_toml(&sm_toml_path)?;

Expand Down Expand Up @@ -202,10 +202,10 @@ pub fn init_package_template(package_info: &PackageInfo, wasi: bool) -> Result<(
})?,
);

let wasmpath = if wasi {
package_info.target_wasm32_wasi_path()?
} else {
let wasmpath = if nowasi {
package_info.target_wasm32_path()?
} else {
package_info.target_wasm32_wasi_path()?
};
pm.manifest.push(
package_meta_relative_path(&package_meta_path, &wasmpath).ok_or_else(|| {
Expand Down
12 changes: 6 additions & 6 deletions crates/smartmodule-development-kit/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use clap::Parser;
use fluvio_future::task::run_block_on;
use fluvio_smartengine::{SmartModuleChainBuilder, SmartModuleConfig, Lookback};
use crate::cmd::PackageCmd;
use crate::ENV_SMDK_WASI;
use crate::ENV_SMDK_NOWASI;

use fluvio_cli_common::smartmodule::{BaseTestCmd, WithChainBuilder};
#[derive(Debug, Parser)]
Expand All @@ -19,8 +19,8 @@ pub struct TestCmd {
package: PackageCmd,
#[arg(long, group = "TestSmartModule")]
wasm_file: Option<PathBuf>,
#[arg(long, env=ENV_SMDK_WASI)]
wasi: bool,
#[arg(long, env=ENV_SMDK_NOWASI, hide_short_help = true)]
nowasi: bool,
}

impl TestCmd {
Expand All @@ -35,10 +35,10 @@ impl TestCmd {
wasm_file
} else {
let package_info = PackageInfo::from_options(&self.package.as_opt())?;
if self.wasi {
package_info.target_wasm32_wasi_path()?
} else {
if self.nowasi {
package_info.target_wasm32_path()?
} else {
package_info.target_wasm32_wasi_path()?
}
};
build_chain_ad_hoc(crate::read_bytes_from_path(&wasm_file)?, params, lookback)
Expand Down
1 change: 1 addition & 0 deletions dev-tools/smartmodule.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ RUN curl -fsS https://hub.infinyon.cloud/install/install.sh?ctx=ci | bash
# add Fluvio smartmodule deps
# source cargo/env is a little bit of a workaround
RUN source "$HOME/.cargo/env" && rustup target install wasm32-unknown-unknown
RUN source "$HOME/.cargo/env" && rustup target install wasm32-wasi
RUN source "$HOME/.cargo/env" && cargo install cargo-generate

# create example-sm dir with a template project in it
Expand Down
4 changes: 2 additions & 2 deletions smartmodule/cargo_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ $ cargo install cargo-generate
$ cargo generate --git https://github.com/infinyon/fluvio-smartmodule-template
```

> **Note**: To compile a SmartModule, you will need to install the `wasm32-unknown-unknown`
> target by running `rustup target add wasm32-unknown-unknown`.
> **Note**: To compile a SmartModule, you will need to install the `wasm32-wasi`
> target by running `rustup target add wasm32-wasi`, or `rustup target add wasm32-unknown-unknown` if using the --nowasi flags
## About SmartModules

Expand Down
2 changes: 1 addition & 1 deletion smartmodule/cargo_template/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "stable"
targets = ["wasm32-unknown-unknown"]
targets = ["wasm32-unknown-unknown", "wasm32-wasi"]
4 changes: 2 additions & 2 deletions smartmodule/examples/Cargo.lock

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

1 change: 1 addition & 0 deletions smartmodule/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ default: build

build:
rustup target add wasm32-unknown-unknown
rustup target add wasm32-wasi
cargo build --release

clean:
Expand Down
Loading

0 comments on commit 438aa15

Please sign in to comment.