Skip to content

Commit

Permalink
fix(Microkernels): Allow compile on Windows where nix crate is not …
Browse files Browse the repository at this point in the history
…functional
  • Loading branch information
nokome committed Dec 10, 2021
1 parent 364c860 commit 8c0e79d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rust/kernel-micro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use kernel::{
stencila_schema::{CodeError, Node},
Kernel, KernelStatus, KernelTrait, KernelType,
};
use nix::{sys::stat, unistd::mkfifo};
use serde::Serialize;
use std::{env, fs};
use tempfile::tempdir;
Expand Down Expand Up @@ -372,6 +371,7 @@ impl KernelTrait for MicroKernel {
}

/// Fork the kernel and execute code in the fork
#[cfg(not(target_os = "windows"))]
async fn fork_exec(&mut self, code: &str) -> Result<(Vec<Node>, Vec<CodeError>)> {
if !self.forkable().await {
tracing::warn!(
Expand All @@ -387,6 +387,7 @@ impl KernelTrait for MicroKernel {
.expect("Kernel should have started and have stdin");

// Create pipes in a temporary directory (which gets cleaned up when dropped)
use nix::{sys::stat, unistd::mkfifo};
let pipes_dir = tempdir().unwrap();
let stdout = pipes_dir.path().join("stdout.pipe");
mkfifo(&stdout, stat::Mode::S_IRWXU)?;
Expand Down
1 change: 1 addition & 0 deletions rust/kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pub trait KernelTrait {
///
/// For more on the "Fork-exec" technique in general see https://en.wikipedia.org/wiki/Fork%E2%80%93exec.
async fn fork_exec(&mut self, code: &str) -> Result<(Vec<Node>, Vec<CodeError>)> {
tracing::warn!("Kernel is not forkable; executing in kernel itself");
self.exec(code).await
}
}
Expand Down

0 comments on commit 8c0e79d

Please sign in to comment.