Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): support compile to wasi target #22870

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(core): disable daemon and pseudo terminal on wasm
  • Loading branch information
FrozenPandaz committed Apr 27, 2024
commit f26badb8c31f796a914c540d17e6ff13c2f6781e
3 changes: 3 additions & 0 deletions packages/nx/src/daemon/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DaemonProjectGraphError,
ProjectGraphError,
} from '../../project-graph/error-types';
import { isWasm } from '../../native';

const DAEMON_ENV_SETTINGS = {
NX_PROJECT_GLOB_CACHE: 'false',
Expand All @@ -49,6 +50,7 @@ enum DaemonStatus {

export class DaemonClient {
private readonly nxJson: NxJsonConfiguration | null;

constructor() {
try {
this.nxJson = readNxJson();
Expand Down Expand Up @@ -93,6 +95,7 @@ export class DaemonClient {
// CI=true,env=false => no daemon
// CI=true,env=true => daemon
if (
isWasm() ||
(isCI() && env !== 'true') ||
isDocker() ||
isDaemonDisabled() ||
Expand Down
2 changes: 2 additions & 0 deletions packages/nx/src/native/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ export interface InputsInput {
projects?: string | Array<string>
}

export function isWasm(): boolean

/** Stripped version of the NxJson interface for use in rust */
export interface NxJson {
namedInputs?: Record<string, Array<JsInputs>>
Expand Down
6 changes: 4 additions & 2 deletions packages/nx/src/native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ pub mod hasher;
mod logger;
pub mod plugins;
pub mod project_graph;
#[cfg(not(target_family = "wasm"))]
#[cfg(not(target_arch = "wasm32"))]
pub mod pseudo_terminal;
pub mod tasks;
mod types;
mod utils;
mod walker;
#[cfg(not(target_family = "wasm"))]
#[cfg(not(target_arch = "wasm32"))]
pub mod watch;
pub mod workspace;

pub mod wasm;
1 change: 1 addition & 0 deletions packages/nx/src/native/native-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ module.exports.findImports = nativeBinding.findImports
module.exports.getFilesForOutputs = nativeBinding.getFilesForOutputs
module.exports.hashArray = nativeBinding.hashArray
module.exports.hashFile = nativeBinding.hashFile
module.exports.isWasm = nativeBinding.isWasm
module.exports.remove = nativeBinding.remove
module.exports.testOnlyTransferFileMap = nativeBinding.testOnlyTransferFileMap
module.exports.transferProjectGraph = nativeBinding.transferProjectGraph
Expand Down
12 changes: 12 additions & 0 deletions packages/nx/src/native/wasm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[napi]
pub fn is_wasm() -> bool {
#[cfg(not(target_arch = "wasm32"))]
{
false
}

#[cfg(target_arch = "wasm32")]
{
true
}
}
5 changes: 4 additions & 1 deletion packages/nx/src/tasks-runner/pseudo-terminal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChildProcess, RustPseudoTerminal } from '../native';
import { ChildProcess, RustPseudoTerminal, isWasm } from '../native';
import { PseudoIPCServer } from './pseudo-ipc';
import { FORKED_PROCESS_OS_SOCKET_PATH } from '../daemon/socket-utils';
import { Serializable } from 'child_process';
Expand Down Expand Up @@ -194,6 +194,9 @@ function messageToCode(message: string): number {
}

function supportedPtyPlatform() {
if (isWasm()) {
return false;
}
if (process.platform !== 'win32') {
return true;
}
Expand Down