Skip to content

Commit

Permalink
feat(core): rust task hasher (nrwl#19617)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli authored Nov 21, 2023
1 parent 4e1289b commit 5d82a2a
Show file tree
Hide file tree
Showing 69 changed files with 3,346 additions and 1,182 deletions.
75 changes: 69 additions & 6 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

[workspace]
resolver = "2"
members = [
'packages/nx'
]
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint/src/executors/lint/hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default async function run(

const nodes = {};
const hashes = [] as string[];
for (const d of Object.keys(res.details.nodes)) {
for (const d of Object.keys(res.details.nodes).sort()) {
if (d.indexOf('$fileset') === -1) {
nodes[d] = res.details.nodes[d];
hashes.push(res.details.nodes[d]);
Expand Down
8 changes: 4 additions & 4 deletions packages/js/src/utils/find-npm-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { join } from 'path';
import { readNxJson } from 'nx/src/config/configuration';
import {
getTargetInputs,
filterUsingGlobPatterns,
} from 'nx/src/hasher/task-hasher';
import {
type ProjectGraph,
type ProjectGraphProjectNode,
Expand All @@ -15,6 +11,10 @@ import {
import { fileExists } from 'nx/src/utils/fileutils';
import { fileDataDepTarget } from 'nx/src/config/project-graph';
import { readTsConfig } from './typescript/ts-config';
import {
filterUsingGlobPatterns,
getTargetInputs,
} from 'nx/src/hasher/task-hasher';

/**
* Finds all npm dependencies and their expected versions for a given project.
Expand Down
4 changes: 4 additions & 0 deletions packages/nx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = '2021'
anyhow = "1.0.71"
colored = "2"
crossbeam-channel = '0.5'
dashmap = { version = "5.5.3", features= ["rayon"] }
fs_extra = "1.3.0"
globset = "0.4.10"
hashbrown = { version = "0.14.0", features = ["rayon"] }
Expand All @@ -24,10 +25,13 @@ napi-derive = '2.9.3'
nom = '7.1.3'
regex = "1.9.1"
rayon = "1.7.0"
serde = "1"
serde_json = "1"
thiserror = "1.0.40"
tokio = { version = "1.28.2", features = ["fs"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tsconfig = "0.2"
walkdir = '2.3.3'
watchexec = "2.3.0"
watchexec-events = "1.0.0"
Expand Down
25 changes: 23 additions & 2 deletions packages/nx/src/command-line/affected/print-affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ import {
mapTargetDefaultsToDependencies,
} from '../../tasks-runner/create-task-graph';
import { NxJsonConfiguration } from '../../config/nx-json';
import { InProcessTaskHasher } from '../../hasher/task-hasher';
import {
DaemonBasedTaskHasher,
InProcessTaskHasher,
TaskHasher,
} from '../../hasher/task-hasher';
import { hashTask } from '../../hasher/hash-task';
import { getPackageManagerCommand } from '../../utils/package-manager';
import { printAffectedDeprecationMessage } from './command-object';
import { logger, NX_PREFIX } from '../../utils/logger';
import { getTaskSpecificEnv } from '../../tasks-runner/task-env';
import { getFileMap } from '../../project-graph/build-project-graph';
import { daemonClient } from '../../daemon/client/client';

/**
* @deprecated Use showProjectsHandler, generateGraph, or affected (without the print-affected mode) instead.
Expand Down Expand Up @@ -72,7 +78,22 @@ async function createTasks(
nxArgs.configuration,
overrides
);
const hasher = new InProcessTaskHasher({}, [], projectGraph, nxJson, {});

let hasher: TaskHasher;
if (daemonClient.enabled()) {
hasher = new DaemonBasedTaskHasher(daemonClient, {});
} else {
const { fileMap, allWorkspaceFiles, rustReferences } = getFileMap();
hasher = new InProcessTaskHasher(
fileMap?.projectFileMap,
allWorkspaceFiles,
projectGraph,
nxJson,
rustReferences,
{}
);
}

const execCommand = getPackageManagerCommand().exec;
const tasks = Object.values(taskGraph.tasks);

Expand Down
8 changes: 4 additions & 4 deletions packages/nx/src/command-line/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { Server } from 'net';
import { FileData } from '../../config/project-graph';
import { TaskGraph } from '../../config/task-graph';
import { daemonClient } from '../../daemon/client/client';
import { filterUsingGlobPatterns } from '../../hasher/task-hasher';
import { getRootTsConfigPath } from '../../plugins/js/utils/typescript';
import { pruneExternalNodes } from '../../project-graph/operators';
import { createProjectGraphAsync } from '../../project-graph/project-graph';
Expand All @@ -42,11 +41,13 @@ import {
import { allFileData } from '../../utils/all-file-data';
import { splitArgsIntoNxArgsAndOverrides } from '../../utils/command-line-utils';
import { NxJsonConfiguration } from '../../config/nx-json';
import { HashPlanner } from '../../native';
import { HashPlanner, transferProjectGraph } from '../../native';
import { transformProjectGraphForRust } from '../../native/transform-objects';
import { getAffectedGraphNodes } from '../affected/affected';
import { readFileMapCache } from '../../project-graph/nx-deps-cache';

import { filterUsingGlobPatterns } from '../../hasher/task-hasher';

export interface ProjectGraphClientResponse {
hash: string;
projects: ProjectGraphProjectNode[];
Expand Down Expand Up @@ -682,9 +683,8 @@ async function createTaskGraphClientResponse(
performance.mark('task graph generation:end');

const planner = new HashPlanner(
workspaceRoot,
nxJson,
transformProjectGraphForRust(graph)
transferProjectGraph(transformProjectGraphForRust(graph))
);
performance.mark('task hash plan generation:start');
const plans: Record<string, string[]> = {};
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/daemon/server/handle-hash-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function handleHashTasks(payload: {
tasks: Task[];
taskGraph: TaskGraph;
}) {
const { projectGraph, allWorkspaceFiles, fileMap } =
const { projectGraph, allWorkspaceFiles, fileMap, rustReferences } =
await getCachedSerializedProjectGraphPromise();
const nxJson = readNxJson();

Expand All @@ -27,6 +27,7 @@ export async function handleHashTasks(payload: {
allWorkspaceFiles,
projectGraph,
nxJson,
rustReferences,
payload.runnerOptions
);
}
Expand Down
Loading

0 comments on commit 5d82a2a

Please sign in to comment.