Skip to content

Commit

Permalink
link against wasmedge static library
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <[email protected]>
  • Loading branch information
jprendes committed Jul 21, 2023
1 parent 8e115f5 commit 7e556ad
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 81 deletions.
18 changes: 1 addition & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ jobs:
- name: Setup OCI runtime build env
run: ${GITHUB_WORKSPACE}/.github/scripts/build.sh
shell: bash
- name: Setup WasmEdge build env
run: |
make bin/wasmedge
echo "LD_LIBRARY_PATH=$PWD/bin/wasmedge/lib" >> $GITHUB_ENV
echo "WASMEDGE_INCLUDE_DIR=$PWD/bin/wasmedge/include" >> $GITHUB_ENV
echo "WASMEDGE_LIB_DIR=$PWD/bin/wasmedge/lib" >> $GITHUB_ENV
- name: Run checks
run: make check
build:
Expand All @@ -43,12 +37,6 @@ jobs:
- name: Setup OCI runtime build env
run: ${GITHUB_WORKSPACE}/.github/scripts/build.sh
shell: bash
- name: Setup WasmEdge build env
run: |
make bin/wasmedge
echo "LD_LIBRARY_PATH=$PWD/bin/wasmedge/lib" >> $GITHUB_ENV
echo "WASMEDGE_INCLUDE_DIR=$PWD/bin/wasmedge/include" >> $GITHUB_ENV
echo "WASMEDGE_LIB_DIR=$PWD/bin/wasmedge/lib" >> $GITHUB_ENV
- name: Build
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -104,11 +92,7 @@ jobs:
run: ${GITHUB_WORKSPACE}/.github/scripts/build.sh
shell: bash
- name: run
run: |
echo "LD_LIBRARY_PATH=$PWD/bin/wasmedge/lib" >> $GITHUB_ENV
echo "WASMEDGE_INCLUDE_DIR=$PWD/bin/wasmedge/include" >> $GITHUB_ENV
echo "WASMEDGE_LIB_DIR=$PWD/bin/wasmedge/lib" >> $GITHUB_ENV
make test/k3s
run: make test/k3s
- name: cleanup
if: always()
run: make test/k3s/clean
5 changes: 0 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ jobs:
- name: Setup build env
run: ${GITHUB_WORKSPACE}/.github/scripts/build.sh
shell: bash
- name: Setup WasmEdge build env
if: ${{ contains(needs.generate.outputs.crate, 'wasmedge' ) }}
run: |
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.13.1
echo "LD_LIBRARY_PATH=$HOME/.wasmedge/lib" >> $GITHUB_ENV
- name: Build
run: cargo build --verbose --package ${{ needs.generate.outputs.crate }}
- name: Test
Expand Down
16 changes: 9 additions & 7 deletions Cargo.lock

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

10 changes: 1 addition & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,14 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx

FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION} AS base
COPY --from=xx / /
RUN apt-get update -y && apt-get install --no-install-recommends -y clang jq
RUN apt-get update -y && apt-get install --no-install-recommends -y clang jq wget

FROM base AS build
SHELL ["/bin/bash", "-c"]
ARG BUILD_TAGS TARGETPLATFORM
ENV WASMEDGE_INCLUDE_DIR=/root/.wasmedge/include
ENV WASMEDGE_LIB_DIR=/root/.wasmedge/lib
ENV LD_LIBRARY_PATH=/root/.wasmedge/lib
RUN xx-apt-get install -y gcc g++ libc++6-dev zlib1g
RUN xx-apt-get install -y pkg-config libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev
RUN rustup target add $(xx-info march)-unknown-$(xx-info os)-$(xx-info libc)
RUN <<EOT
set -ex
os=$(xx-info os)
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.13.1 --platform=${os^} --machine=$(xx-info march)
EOT

WORKDIR /build/src
COPY --link crates ./crates
Expand Down
22 changes: 2 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ INSTALL ?= install
TEST_IMG_NAME ?= wasmtest:latest
RUNTIMES ?= wasmedge wasmtime
export CONTAINERD_NAMESPACE ?= default
export WASMEDGE_INCLUDE_DIR ?=$(PWD)/bin/wasmedge/include
export WASMEDGE_LIB_DIR ?=$(PWD)/bin/wasmedge/lib

TARGET ?= debug
RELEASE_FLAG :=
Expand Down Expand Up @@ -83,17 +81,6 @@ test/k8s: test/k8s/cluster
test/k8s/clean: bin/kind
bin/kind delete cluster --name $(KIND_CLUSTER_NAME)

.PHONY: bin/wasmedge
bin/wasmedge:
mkdir -p ${CURDIR}/bin
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.13.1 -p $(PWD)/bin/wasmedge && \
sudo -E sh -c 'echo "$(PWD)/bin/wasmedge/lib" > /etc/ld.so.conf.d/libwasmedge.conf' && sudo ldconfig

.PHONY: bin/wasmedge/clean
bin/wasmedge/clean:
sudo rm /etc/ld.so.conf.d/libwasmedge.conf && sudo ldconfig
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/uninstall.sh | bash -s -- -p $(PWD)/bin/wasmedge -q

.PHONY: bin/k3s
bin/k3s:
mkdir -p bin && \
Expand All @@ -104,16 +91,12 @@ bin/k3s/clean:
bin/k3s-runwasi-uninstall.sh

.PHONY: test/k3s
test/k3s: target/wasm32-wasi/$(TARGET)/img.tar bin/wasmedge bin/k3s
export WASMEDGE_INCLUDE_DIR=$(PWD)/bin/wasmedge/include && \
export WASMEDGE_LIB_DIR=$(PWD)/bin/wasmedge/lib && \
test/k3s: target/wasm32-wasi/$(TARGET)/img.tar bin/k3s
cargo build $(RELEASE_FLAG) && \
cp target/$(TARGET)/containerd-shim-wasmedge-v1 $(PWD)/bin/ && \
sudo cp /var/lib/rancher/k3s/agent/etc/containerd/config.toml /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl && \
echo '[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasm]' | sudo tee -a /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl && \
echo ' runtime_type = "$(PWD)/bin/containerd-shim-wasmedge-v1"' | sudo tee -a /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl && \
echo ' [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasm.options]' | sudo tee -a /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl && \
echo ' BinaryName = "$(PWD)/bin/wasmedge/bin/wasmedge"' | sudo tee -a /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl && \
echo "CONTAINERD_NAMESPACE='default'" | sudo tee /etc/systemd/system/k3s-runwasi.service.env && \
echo "NO_PROXY=192.168.0.0/16" | sudo tee -a /etc/systemd/system/k3s-runwasi.service.env && \
sudo systemctl daemon-reload && \
Expand All @@ -125,7 +108,6 @@ test/k3s: target/wasm32-wasi/$(TARGET)/img.tar bin/wasmedge bin/k3s
sudo bin/k3s kubectl get pods -o wide

.PHONY: test/k3s/clean
test/k3s/clean: bin/wasmedge/clean bin/k3s/clean
test/k3s/clean: bin/k3s/clean
cargo clean
unset WASMEDGE_INCLUDE_DIR WASMEDGE_LIB_DIR
rm $(PWD)/bin/containerd-shim-wasmedge-v1
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,7 @@ You will need to make sure the `containerd-[ wasmedge | wasmtime ]d` daemon has

#### Building

1. Install Wasm Edge dependencies

```terminal
make bin/wasmedge/clean
make bin/wasmedge
```

2. Install [youki dependencies](https://github.com/containers/youki#dependencies)
1. Install [youki dependencies](https://github.com/containers/youki#dependencies)

```
sudo apt-get install \
Expand All @@ -167,7 +160,7 @@ sudo apt-get install \
libssl-dev
```

3. Build
2. Build

```
make build
Expand Down
2 changes: 1 addition & 1 deletion crates/containerd-shim-wasmedge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ containerd-shim = { workspace = true }
containerd-shim-wasm = { workspace = true }
log = { workspace = true }
ttrpc = { workspace = true }
wasmedge-sdk = "0.9.0"
chrono = { workspace = true }
anyhow = { workspace = true }
cap-std = { workspace = true }
wasmedge-sdk = { version = "0.10.0", features = [ "standalone", "static" ] }
oci-spec = { workspace = true, features = ["runtime"] }
thiserror = { workspace = true }
serde = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ use containerd_shim_wasm::sandbox::ShimCli;
use containerd_shim_wasmedge::instance::Wasi as WasiInstance;

fn main() {
shim::run::<ShimCli<WasiInstance, wasmedge_sdk::Vm<wasmedge_sdk::NeverType>>>(
"io.containerd.wasmedge.v1",
None,
);
shim::run::<ShimCli<WasiInstance, wasmedge_sdk::Vm>>("io.containerd.wasmedge.v1", None);
}
6 changes: 3 additions & 3 deletions crates/containerd-shim-wasmedge/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::os::unix::io::RawFd;

use wasmedge_sdk::{
config::{CommonConfigOptions, ConfigBuilder, HostRegistrationConfigOptions},
params, NeverType, VmBuilder,
params, VmBuilder,
};

const EXECUTOR_NAME: &str = "wasmedge";
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Executor for WasmEdgeExecutor {
}

impl WasmEdgeExecutor {
fn prepare(&self, args: &[String], spec: &Spec) -> anyhow::Result<wasmedge_sdk::Vm<NeverType>> {
fn prepare(&self, args: &[String], spec: &Spec) -> anyhow::Result<wasmedge_sdk::Vm> {
let mut cmd = args[0].clone();
if let Some(stripped) = args[0].strip_prefix(std::path::MAIN_SEPARATOR) {
cmd = stripped.to_string();
Expand All @@ -62,7 +62,7 @@ impl WasmEdgeExecutor {
.map_err(|err| ExecutorError::Execution(err))?;
let mut vm = VmBuilder::new()
.with_config(config)
.build::<NeverType>()
.build()
.map_err(|err| ExecutorError::Execution(err))?;
let wasi_module = vm
.wasi_module_mut()
Expand Down
8 changes: 4 additions & 4 deletions crates/containerd-shim-wasmedge/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use serde::{Deserialize, Serialize};
use wasmedge_sdk::{
config::{CommonConfigOptions, ConfigBuilder, HostRegistrationConfigOptions},
plugin::PluginManager,
NeverType, Vm, VmBuilder,
Vm, VmBuilder,
};

use std::{
Expand Down Expand Up @@ -98,7 +98,7 @@ fn determine_rootdir<P: AsRef<Path>>(bundle: P, namespace: String) -> Result<Pat
}

impl Instance for Wasi {
type E = Vm<NeverType>;
type E = Vm;
fn new(id: String, cfg: Option<&InstanceConfig<Self::E>>) -> Self {
let cfg = cfg.unwrap(); // TODO: handle error
let bundle = cfg.get_bundle().unwrap_or_default();
Expand Down Expand Up @@ -250,8 +250,8 @@ impl Wasi {
}

impl EngineGetter for Wasi {
type E = Vm<NeverType>;
fn new_engine() -> Result<Vm<NeverType>, Error> {
type E = Vm;
fn new_engine() -> Result<Vm, Error> {
PluginManager::load(None).unwrap();
let mut host_options = HostRegistrationConfigOptions::default();
host_options = host_options.wasi(true);
Expand Down
3 changes: 1 addition & 2 deletions test/k8s/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup install stable
WORKDIR /shim
COPY . .
RUN apt-get update && apt-get install --no-install-recommends -y build-essential git clang pkg-config libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev
RUN curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.13.1
RUN apt-get update && apt-get install --no-install-recommends -y build-essential git clang wget pkg-config libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev
RUN \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/shim/target \
Expand Down

0 comments on commit 7e556ad

Please sign in to comment.