You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.1 KiB
Markdown
54 lines
2.1 KiB
Markdown
+++
|
|
title = "[TRIAGE] workers-rs compatibility with native Rust test binaries (may need separate native feature flag)"
|
|
priority = 9
|
|
status = "done"
|
|
ticket_type = "task"
|
|
dependencies = []
|
|
+++
|
|
|
|
<context>
|
|
This is a triage decision ticket. It must be resolved before dependent implementation tickets can proceed.
|
|
</context>
|
|
|
|
<question>
|
|
workers-rs compatibility with native Rust test binaries: the workers-rs crate targets the Cloudflare Workers runtime, not native Linux/macOS. Can the API code be compiled as a native binary for `cargo test`?
|
|
</question>
|
|
|
|
<options>
|
|
1. **Conditional compilation** — use `#[cfg(target_env = "worker")]` to switch between workers-rs entry point and a plain Axum server. The native build is used for testing.
|
|
2. **Feature flags** — add a `native` feature that enables the Axum server path. `cargo test` uses `--features native`.
|
|
3. **Separate test binary** — integration tests spawn a separately compiled native test server binary.
|
|
</options>
|
|
|
|
<decision>
|
|
**Option 1 variant: `cfg(target_arch = "wasm32")` — no feature flag needed.**
|
|
|
|
Note: `target_env = "worker"` is incorrect. The right discriminant is `target_arch = "wasm32"`.
|
|
|
|
The `cfg(target_arch)` split is cleaner than a feature flag because it is tied to the actual
|
|
build target, not an opt-in flag that could be forgotten:
|
|
|
|
- `[target.'cfg(target_arch = "wasm32")'.dependencies]` → workers-rs (pulled in only for WASM)
|
|
- `[target.'cfg(not(target_arch = "wasm32"))'.dependencies]` → tokio, axum, rusqlite (native only)
|
|
|
|
In `main.rs`:
|
|
```rust
|
|
#[cfg(target_arch = "wasm32")]
|
|
#[worker::event(fetch)]
|
|
pub async fn main(...) { /* workers-rs entry point */ }
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
#[tokio::main]
|
|
async fn main() { /* native Axum server on :8080 */ }
|
|
```
|
|
|
|
`cargo test` (native host) automatically compiles the native path. No special flags.
|
|
No feature flag pollution. Resolved as part of TRIAGE e8a330 (DB strategy decision).
|
|
|
|
See implementation ticket 00aff0 for full details.
|
|
</decision>
|
|
|
|
<commit>
|
|
`chore(quotesdb): resolve triage — workersrs-compatibility-with-native-rust-test-binaries-may-n`
|
|
</commit>
|