Skip to content

Commit

Permalink
fastly_vcpu -> fastly_compute_runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
acw committed Jul 31, 2024
1 parent 06114ee commit ff726ec
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions crates/adapter/src/fastly/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ pub mod fastly_abi {
}
}

pub mod fastly_vcpu {
pub mod fastly_compute_runtime {
use super::*;

#[export_name = "fastly_vcpu#get_vcpu_ms"]
#[export_name = "fastly_compute_runtime#get_vcpu_ms"]
pub fn get_vcpu_ms(vcpu_time_ms_out: *mut u64) -> FastlyStatus {
match crate::bindings::fastly::api::vcpu::get_vcpu_ms() {
match crate::bindings::fastly::api::compute_runtime::get_vcpu_ms() {
Ok(time) => {
unsafe {
*vcpu_time_ms_out = time;
Expand Down
2 changes: 1 addition & 1 deletion lib/compute-at-edge-abi/compute-at-edge.witx
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@
)
)

(module $fastly_vcpu
(module $fastly_compute_runtime
(@interface func (export "get_vcpu_ms")
(result $err (expected $vcpu_ms (error $fastly_status)))
)
Expand Down
Binary file modified lib/data/viceroy-component-adapter.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::fastly::api::{types, vcpu};
use super::fastly::api::{types, compute_runtime};
use crate::session::Session;
use std::sync::atomic::Ordering;

#[async_trait::async_trait]
impl vcpu::Host for Session {
impl compute_runtime::Host for Session {
async fn get_vcpu_ms(&mut self) -> Result<u64, types::Error> {
Ok(self.active_cpu_time_us.load(Ordering::SeqCst) / 1000)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ pub fn link_host_functions(linker: &mut component::Linker<ComponentCtx>) -> anyh
fastly::api::types::add_to_linker(linker, |x| x.session())?;
fastly::api::uap::add_to_linker(linker, |x| x.session())?;
fastly::api::config_store::add_to_linker(linker, |x| x.session())?;
fastly::api::vcpu::add_to_linker(linker, |x| x.session())?;
fastly::api::compute_runtime::add_to_linker(linker, |x| x.session())?;

Ok(())
}

pub mod async_io;
pub mod backend;
pub mod cache;
pub mod compute_runtime;
pub mod config_store;
pub mod device_detection;
pub mod dictionary;
Expand All @@ -84,4 +85,3 @@ pub mod purge;
pub mod secret_store;
pub mod types;
pub mod uap;
pub mod vcpu;
2 changes: 1 addition & 1 deletion lib/src/linking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ pub fn link_host_functions(
wiggle_abi::fastly_uap::add_to_linker(linker, WasmCtx::session)?;
wiggle_abi::fastly_async_io::add_to_linker(linker, WasmCtx::session)?;
wiggle_abi::fastly_backend::add_to_linker(linker, WasmCtx::session)?;
wiggle_abi::fastly_vcpu::add_to_linker(linker, WasmCtx::session)?;
wiggle_abi::fastly_compute_runtime::add_to_linker(linker, WasmCtx::session)?;
link_legacy_aliases(linker)?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/wiggle_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ macro_rules! multi_value_result {
mod backend_impl;
mod body_impl;
mod cache;
mod compute_runtime;
mod config_store;
mod device_detection_impl;
mod dictionary_impl;
Expand All @@ -65,7 +66,6 @@ mod req_impl;
mod resp_impl;
mod secret_store_impl;
mod uap_impl;
mod vcpu;

// Expand the `.witx` interface definition into a collection of modules. The `types` module will
// contain all of the `typename`'s defined in the `witx` file, and other modules will export traits
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::error::Error;
use crate::session::Session;
use crate::wiggle_abi::fastly_vcpu::FastlyVcpu;
use crate::wiggle_abi::fastly_compute_runtime::FastlyComputeRuntime;
use std::sync::atomic::Ordering;
use wiggle::GuestMemory;

impl FastlyVcpu for Session {
impl FastlyComputeRuntime for Session {
fn get_vcpu_ms(&mut self, _memory: &mut GuestMemory<'_>) -> Result<u64, Error> {
// we internally track microseconds, because our wasmtime tick length
// is too short for ms to work. but we want to shrink this to ms to
Expand Down
4 changes: 2 additions & 2 deletions lib/wit/deps/fastly/compute.wit
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ interface reactor {
serve: func(req: request-handle, body: body-handle) -> result;
}

interface vcpu {
interface compute-runtime {
use types.{error};

type vcpu-ms = u64;
Expand All @@ -1109,6 +1109,7 @@ world compute {
import async-io;
import backend;
import cache;
import compute-runtime;
import dictionary;
import geo;
import device-detection;
Expand All @@ -1122,7 +1123,6 @@ world compute {
import secret-store;
import config-store;
import uap;
import vcpu;

export reactor;
}
2 changes: 1 addition & 1 deletion test-fixtures/src/bin/vcpu_time_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hex_literal::hex;
use sha2::{Sha512, Digest};
use std::time::{Duration, Instant};

#[link(wasm_import_module = "fastly_vcpu")]
#[link(wasm_import_module = "fastly_compute_runtime")]
extern "C" {
#[link_name = "get_vcpu_ms"]
pub fn get_vcpu_ms(ms_out: *mut u64) -> FastlyStatus;
Expand Down

0 comments on commit ff726ec

Please sign in to comment.