Skip to content

Commit

Permalink
feat(core): include target architecture in nx report
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Jul 24, 2024
1 parent 28cd0c4 commit a38df9b
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 21 deletions.
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/nx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ strip = "none"
[dependencies]
anyhow = "1.0.71"
colored = "2"
const_format = "0.2.32"
crossbeam-channel = '0.5'
dashmap = { version = "5.5.3", features = ["rayon"] }
dunce = "1"
Expand Down
24 changes: 16 additions & 8 deletions packages/nx/src/command-line/report/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ export async function reportHandler() {
packageVersionsWeCareAbout,
outOfSyncPackageGroup,
projectGraphError,
nativeTarget,
} = await getReportData();

const bodyLines = [
`Node : ${process.versions.node}`,
`OS : ${process.platform}-${process.arch}`,
`${pm.padEnd(7)}: ${pmVersion}`,
``,
const fields = [
['Node', process.versions.node],
['OS', `${process.platform}-${process.arch}`],
['NATIVE TARGET', nativeTarget ?? 'Unavailable'],
[pm, pmVersion],
];
const maxFieldLength = Math.max(...fields.map((f) => f[0].length));
const bodyLines = fields.map(
([field, value]) => `${field.padEnd(maxFieldLength)} : ${value}`
);

let padding =
Math.max(...packageVersionsWeCareAbout.map((x) => x.package.length)) + 1;
Expand Down Expand Up @@ -156,6 +161,7 @@ export interface ReportData {
migrateTarget: string;
};
projectGraphError?: Error | null;
nativeTarget: string | null;
}

export async function getReportData(): Promise<ReportData> {
Expand Down Expand Up @@ -183,6 +189,8 @@ export async function getReportData(): Promise<ReportData> {

const outOfSyncPackageGroup = findMisalignedPackagesForPackage(nxPackageJson);

const native = isNativeAvailable();

return {
pm,
pmVersion,
Expand All @@ -192,6 +200,7 @@ export async function getReportData(): Promise<ReportData> {
packageVersionsWeCareAbout,
outOfSyncPackageGroup,
projectGraphError,
nativeTarget: native ? native.getBinaryTarget() : null,
};
}

Expand Down Expand Up @@ -351,10 +360,9 @@ export function findInstalledPackagesWeCareAbout() {
}));
}

function isNativeAvailable() {
function isNativeAvailable(): typeof import('../../native') | false {
try {
require('../../native');
return true;
return require('../../native');
} catch {
return false;
}
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 @@ -116,6 +116,8 @@ export interface FileSetInput {

export declare export function findImports(projectFileMap: Record<string, Array<string>>): Array<ImportResult>

export declare export function getBinaryTarget(): string

/**
* Expands the given outputs into a list of existing files.
* This is used when hashing outputs
Expand Down
30 changes: 30 additions & 0 deletions packages/nx/src/native/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#[napi]
#[cfg(target_arch = "wasm32")]
pub const IS_WASM: bool = true;

#[napi]
#[cfg(not(target_arch = "wasm32"))]
pub const IS_WASM: bool = false;

use std::env::consts;

#[napi]
pub fn get_binary_target() -> String {
let arch = consts::ARCH;
let os = consts::OS;

let mut binary_target = String::new();

if !arch.is_empty() {
binary_target.push_str(&arch);
}

if !os.is_empty() {
if !binary_target.is_empty() {
binary_target.push('-');
}
binary_target.push_str(&os);
}

binary_target
}
10 changes: 5 additions & 5 deletions packages/nx/src/native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ pub mod cache;
pub mod glob;
pub mod hasher;
mod logger;
pub mod metadata;
pub mod plugins;
pub mod project_graph;
#[cfg(not(target_arch = "wasm32"))]
pub mod pseudo_terminal;
pub mod tasks;
mod types;
mod utils;
mod walker;
#[cfg(not(target_arch = "wasm32"))]
pub mod watch;
pub mod workspace;

pub mod wasm;
#[cfg(not(target_arch = "wasm32"))]
pub mod pseudo_terminal;
#[cfg(not(target_arch = "wasm32"))]
pub mod watch;
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 @@ -372,6 +372,7 @@ module.exports.copy = nativeBinding.copy
module.exports.EventType = nativeBinding.EventType
module.exports.expandOutputs = nativeBinding.expandOutputs
module.exports.findImports = nativeBinding.findImports
module.exports.getBinaryTarget = nativeBinding.getBinaryTarget
module.exports.getFilesForOutputs = nativeBinding.getFilesForOutputs
module.exports.hashArray = nativeBinding.hashArray
module.exports.hashFile = nativeBinding.hashFile
Expand Down
1 change: 0 additions & 1 deletion packages/nx/src/native/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub use find_matching_projects::*;
pub use get_mod_time::*;
pub use normalize_trait::Normalize;


#[cfg_attr(not(target_arch = "wasm32"), path = "atomics/default.rs")]
#[cfg_attr(target_arch = "wasm32", path = "atomics/wasm.rs")]
pub mod atomics;
Expand Down
7 changes: 0 additions & 7 deletions packages/nx/src/native/wasm.rs

This file was deleted.

0 comments on commit a38df9b

Please sign in to comment.