Skip to content

Commit ce2397a

Browse files
committed
fix: 'cargo build' with non-wasm targets
1 parent 68fa27d commit ce2397a

File tree

32 files changed

+124
-111
lines changed

32 files changed

+124
-111
lines changed

aicirt/src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use crate::HashMap;
12
use aici_abi::{StorageCmd, TokenId};
23
use serde::{Deserialize, Serialize};
34
use serde_json::Value;
4-
use crate::HashMap;
55

66
pub type ModuleInstId = u64;
77

aicirt/src/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use crate::HashMap;
12
use std::{
23
fmt::{Display, Write},
34
sync::{Arc, Mutex},
45
time::{Duration, Instant},
56
};
6-
use crate::HashMap;
77

88
#[derive(PartialEq, Eq)]
99
enum TimerState {

aicirt/src/bindings.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use wasmtime::component::bindgen;
33

44
bindgen!("aici" in "../wit");
55

6-
pub use self::aici::abi::runtime::SeqId;
7-
pub use self::aici::abi::tokenizer::TokenId;
8-
pub use self::exports::aici::abi::controller::*;
6+
pub use self::{
7+
aici::abi::{runtime::SeqId, tokenizer::TokenId},
8+
exports::aici::abi::controller::*,
9+
};
910

1011
pub trait Json {
1112
fn to_json(&self) -> String;
@@ -31,9 +32,6 @@ impl From<()> for PreProcessArg {
3132
}
3233
}
3334

34-
35-
36-
3735
#[derive(Serialize, Deserialize)]
3836
#[serde(remote = "Vocabulary")]
3937
struct VocabularyDef {
@@ -92,7 +90,6 @@ struct PostProcessResultDef {
9290
stop: bool,
9391
}
9492

95-
9693
macro_rules! serde_wrapper {
9794
($name:ident, $wrapper:ident) => {
9895
impl Serialize for $name {

aicirt/src/futexshm.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use crate::shm::{Shm, Unlink};
22
use anyhow::{anyhow, Result};
3+
#[cfg(target_os = "linux")]
4+
use linux_futex::AsFutex;
35
use serde::{Deserialize, Serialize};
46
use std::{
57
ptr,
68
sync::atomic::{AtomicU32, Ordering},
79
time::{Duration, Instant},
810
};
9-
10-
#[cfg(target_os = "linux")]
11-
use linux_futex::AsFutex;
1211
#[cfg(target_os = "linux")]
1312
type Futex = linux_futex::Futex<linux_futex::Shared>;
1413

aicirt/src/hostimpl.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{
22
bindings::aici::abi::{self, tokenizer::TokenId},
3-
shm::Shm,
43
worker::{GroupCmd, GroupHandle, GroupResp},
54
};
65
use aici_abi::{
@@ -192,9 +191,9 @@ impl abi::runtime_storage::Host for ModuleData {
192191

193192
match res {
194193
GroupResp::StorageResp { resp } => match resp {
195-
aici_abi::StorageResp::ReadVar { version, value } => Ok(Some(value)),
194+
aici_abi::StorageResp::ReadVar { version: _, value } => Ok(Some(value)),
196195
aici_abi::StorageResp::VariableMissing {} => Ok(None),
197-
aici_abi::StorageResp::WriteVar { version } => Err(anyhow!("unexpected WriteVar")),
196+
aici_abi::StorageResp::WriteVar { .. } => Err(anyhow!("unexpected WriteVar")),
198197
},
199198
}
200199
}
@@ -210,13 +209,11 @@ impl abi::runtime_storage::Host for ModuleData {
210209
let res = self.group_channel.send_cmd(GroupCmd::StorageCmd { cmd })?;
211210
match res {
212211
GroupResp::StorageResp { resp } => match resp {
213-
aici_abi::StorageResp::ReadVar { version, value } => {
214-
Err(anyhow!("unexpected ReadVar"))
215-
}
216-
aici_abi::StorageResp::VariableMissing {} => {
212+
aici_abi::StorageResp::ReadVar { .. } => Err(anyhow!("unexpected ReadVar")),
213+
aici_abi::StorageResp::VariableMissing { .. } => {
217214
Err(anyhow!("unexpected VariableMissing"))
218215
}
219-
aici_abi::StorageResp::WriteVar { version } => Ok(()),
216+
aici_abi::StorageResp::WriteVar { .. } => Ok(()),
220217
},
221218
}
222219
}
@@ -232,13 +229,11 @@ impl abi::runtime_storage::Host for ModuleData {
232229
let res = self.group_channel.send_cmd(GroupCmd::StorageCmd { cmd })?;
233230
match res {
234231
GroupResp::StorageResp { resp } => match resp {
235-
aici_abi::StorageResp::ReadVar { version, value } => {
236-
Err(anyhow!("unexpected ReadVar"))
237-
}
238-
aici_abi::StorageResp::VariableMissing {} => {
232+
aici_abi::StorageResp::ReadVar { .. } => Err(anyhow!("unexpected ReadVar")),
233+
aici_abi::StorageResp::VariableMissing { .. } => {
239234
Err(anyhow!("unexpected VariableMissing"))
240235
}
241-
aici_abi::StorageResp::WriteVar { version } => Ok(()),
236+
aici_abi::StorageResp::WriteVar { .. } => Ok(()),
242237
},
243238
}
244239
}

aicirt/src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
pub mod api;
22
mod bench;
3+
pub mod bindings;
34
pub mod bintokens;
45
pub mod futexshm;
56
pub mod msgchannel;
67
pub mod semaphore;
78
pub mod shm;
8-
pub mod bindings;
99

1010
#[cfg(target_os = "macos")]
1111
mod macos;
1212

13-
use std::fmt::Write;
14-
1513
use anyhow::Result;
1614
pub use bench::*;
17-
use flexi_logger::style;
18-
use flexi_logger::{DeferredNow, Logger, WriteMode};
15+
use flexi_logger::{style, DeferredNow, Logger, WriteMode};
16+
pub use fxhash::{FxHashMap as HashMap, FxHashSet as HashSet};
1917
use log::Record;
18+
use std::fmt::Write;
2019
use thread_priority::{
2120
set_thread_priority_and_policy, thread_native_id, RealtimeThreadSchedulePolicy, ThreadPriority,
2221
ThreadSchedulePolicy,
2322
};
2423

25-
pub use fxhash::FxHashMap as HashMap;
26-
pub use fxhash::FxHashSet as HashSet;
27-
2824
pub enum LogMode {
2925
Normal,
3026
Test,

aicirt/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::{
1313
};
1414
use aici_abi::{bytes::limit_str, toktree::TokTrie};
1515
use aicirt::{
16-
bintokens::find_tokenizer,
1716
bindings::{MidProcessArg, PostProcessArg, PreProcessArg, SeqId},
17+
bintokens::find_tokenizer,
1818
futexshm::ServerChannel,
1919
*,
2020
};

aicirt/src/moduleinstance.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ use crate::{
99
use aici_abi::toktree::TokTrie;
1010
use aicirt::{
1111
api::{AiciMidProcessResultInner, AiciPostProcessResultInner, SequenceResult},
12-
bintokens::ByteTokenizer,
1312
bindings::{self, exports::aici::abi::controller::*, InitPromptResult, PreProcessArg},
13+
bintokens::ByteTokenizer,
1414
user_error,
1515
};
1616
use anyhow::{bail, ensure, Result};
17-
use serde::Deserialize;
1817
use std::{path::Path, sync::Arc, time::Instant};
1918
use wasmtime;
2019

@@ -124,7 +123,10 @@ impl ModuleInstance {
124123

125124
let component_instance = ctx.component_linker.instantiate(&mut store, &component)?;
126125
let aici = bindings::Aici::new(&mut store, &component_instance)?;
127-
let runner = aici.aici_abi_controller().runner().call_constructor(&mut store, &module_arg)?;
126+
let runner = aici
127+
.aici_abi_controller()
128+
.runner()
129+
.call_constructor(&mut store, &module_arg)?;
128130

129131
Ok(ModuleInstance {
130132
store,
@@ -187,13 +189,15 @@ impl ModuleInstance {
187189
.call_pre_process(&mut self.store, self.runner)
188190
}
189191

190-
fn do_mid_process(&mut self, op: RtMidProcessArg, shm: &Shm) -> Result<Option<AiciMidProcessResultInner>> {
192+
fn do_mid_process(
193+
&mut self,
194+
op: RtMidProcessArg,
195+
shm: &Shm,
196+
) -> Result<Option<AiciMidProcessResultInner>> {
191197
let vocab_size = self.store.data().globals.tokrx_info.vocab_size as usize;
192198
assert!(op.logit_size == vocab_size * 4);
193199
let logit_ptr = shm.slice_at_byte_offset(op.logit_offset, vocab_size);
194-
logit_ptr
195-
.iter_mut()
196-
.for_each(|x| *x = LOGIT_BIAS_DISALLOW);
200+
logit_ptr.iter_mut().for_each(|x| *x = LOGIT_BIAS_DISALLOW);
197201

198202
match self.aici.aici_abi_controller().runner().call_mid_process(
199203
&mut self.store,
@@ -209,12 +213,10 @@ impl ModuleInstance {
209213
}
210214
}
211215
Ok(None)
212-
},
216+
}
213217
MidProcessResult::Stop { .. } => {
214218
let eos = self.store.data().globals.tokrx_info.tok_eos;
215-
logit_ptr
216-
.iter_mut()
217-
.for_each(|v| *v = LOGIT_BIAS_DISALLOW);
219+
logit_ptr.iter_mut().for_each(|v| *v = LOGIT_BIAS_DISALLOW);
218220
logit_ptr[eos as usize] = LOGIT_BIAS_ALLOW;
219221
Ok(None)
220222
}
@@ -242,9 +244,7 @@ impl ModuleInstance {
242244
} else {
243245
// we don't really care about biases, as we'lre going to backtrack this token anyways
244246
// but just in case, allow all
245-
logit_ptr
246-
.iter_mut()
247-
.for_each(|v| *v = LOGIT_BIAS_DISALLOW);
247+
logit_ptr.iter_mut().for_each(|v| *v = LOGIT_BIAS_DISALLOW);
248248
// don't remove anything from ff_tokens - they all need to be appended after backtracking
249249

250250
// backtrack needs to include also the next token to be generated

aicirt/src/msgchannel.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::{semaphore::Semaphore, shm::{Shm, Unlink}};
1+
use crate::{
2+
semaphore::Semaphore,
3+
shm::{Shm, Unlink},
4+
};
25
use anyhow::Result;
36
use std::time::Duration;
47

aicirt/src/worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::{
88
};
99
use aici_abi::{StorageCmd, StorageOp, StorageResp};
1010
use aicirt::{
11-
bindings::*,
1211
api::{AiciMidProcessResultInner, AiciPostProcessResultInner, SequenceResult},
12+
bindings::*,
1313
futexshm::{TypedClient, TypedClientHandle, TypedServer},
1414
set_max_priority,
1515
shm::Unlink,

0 commit comments

Comments
 (0)