Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
47835e6c
Unverified
Commit
47835e6c
authored
Jun 25, 2025
by
Tobias Koppers
Committed by
GitHub
Jun 25, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add turbo tasks fuzzing (#79372)
### What? Add fuzz testing for turbo-tasks-backend
parent
c71f8b0c
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
593 additions
and
19 deletions
+593
-19
Cargo.lock
Cargo.lock
+53
-5
Cargo.toml
Cargo.toml
+2
-1
.gitignore
turbopack/crates/turbo-tasks-backend/fuzz/.gitignore
+3
-0
Cargo.toml
turbopack/crates/turbo-tasks-backend/fuzz/Cargo.toml
+37
-0
empty
turbopack/crates/turbo-tasks-backend/fuzz/afl-in/empty
+0
-0
graph.rs
...pack/crates/turbo-tasks-backend/fuzz/afl_targets/graph.rs
+26
-0
build.rs
turbopack/crates/turbo-tasks-backend/fuzz/build.rs
+5
-0
graph.rs
...ack/crates/turbo-tasks-backend/fuzz/fuzz_targets/graph.rs
+23
-0
graph.rs
turbopack/crates/turbo-tasks-backend/fuzz/src/graph.rs
+167
-0
mod.rs
turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
+6
-1
storage.rs
turbopack/crates/turbo-tasks-backend/src/backend/storage.rs
+13
-4
bug.rs
turbopack/crates/turbo-tasks-backend/tests/bug.rs
+195
-0
lib.rs
turbopack/crates/turbo-tasks-build/src/lib.rs
+63
-8
No files found.
Cargo.lock
View file @
47835e6c
...
...
@@ -33,6 +33,18 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "afl"
version = "0.15.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eda81c043843d2eeb489c3f30774953326fa043b7a6470d4c2ad7c3cdfd9847b"
dependencies = [
"home",
"libc",
"rustc_version",
"xdg",
]
[[package]]
name = "ahash"
version = "0.7.8"
...
...
@@ -241,9 +253,12 @@ dependencies = [
[[package]]
name = "arbitrary"
version = "1.
3.2
"
version = "1.
4.1
"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110"
checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223"
dependencies = [
"derive_arbitrary",
]
[[package]]
name = "arc-swap"
...
...
@@ -1852,6 +1867,17 @@ dependencies = [
"serde",
]
[[package]]
name = "derive_arbitrary"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30542c1ad912e0e3d22a1935c290e12e8a29d704a420177a31faad4a601a0800"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.100",
]
[[package]]
name = "derive_builder"
version = "0.12.0"
...
...
@@ -3561,13 +3587,12 @@ checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "libfuzzer-sys"
version = "0.4.
7
"
version = "0.4.
9
"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
a96cfd5557eb82f2b83fed4955246c988d331975a002961b07c81584d107e7f7
"
checksum = "
cf78f52d400cf2d84a3a973a78a592b4adc535739e0a5597a0da6f0c357adc75
"
dependencies = [
"arbitrary",
"cc",
"once_cell",
]
[[package]]
...
...
@@ -9246,6 +9271,23 @@ dependencies = [
"turbo-tasks-testing",
]
[[package]]
name = "turbo-tasks-backend-fuzz"
version = "0.0.0"
dependencies = [
"afl",
"anyhow",
"arbitrary",
"libfuzzer-sys",
"once_cell",
"serde",
"tokio",
"turbo-tasks",
"turbo-tasks-backend",
"turbo-tasks-build",
"turbo-tasks-malloc",
]
[[package]]
name = "turbo-tasks-build"
version = "0.1.0"
...
...
@@ -11488,6 +11530,12 @@ dependencies = [
"rustix 0.38.41",
]
[[package]]
name = "xdg"
version = "2.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
[[package]]
name = "xtask"
version = "0.1.0"
...
...
Cargo.toml
View file @
47835e6c
...
...
@@ -11,6 +11,7 @@ members = [
"crates/next-core"
,
"crates/next-custom-transforms"
,
"turbopack/crates/*"
,
"turbopack/crates/*/fuzz"
,
"turbopack/xtask"
,
]
...
...
@@ -20,7 +21,7 @@ exclude = ["crates/next-error-code-swc-plugin"]
too_many_arguments
=
"allow"
[workspace.lints.rust]
unexpected_cfgs
=
{
level
=
"warn"
,
check-cfg
=
['cfg(rust_analyzer)']
}
unexpected_cfgs
=
{
level
=
"warn"
,
check-cfg
=
[
'cfg(rust_analyzer)'
,
'cfg(fuzzing)'
]
}
# This crate is particularly sensitive to compiler optimizations
[profile.dev.package.turbo-persistence]
...
...
turbopack/crates/turbo-tasks-backend/fuzz/.gitignore
0 → 100644
View file @
47835e6c
artifacts
corpus
afl-out
turbopack/crates/turbo-tasks-backend/fuzz/Cargo.toml
0 → 100644
View file @
47835e6c
[package]
name
=
"turbo-tasks-backend-fuzz"
version
=
"0.0.0"
publish
=
false
edition
=
"2024"
[package.metadata]
cargo-fuzz
=
true
[dependencies]
afl
=
"0.15.18"
anyhow
=
{
workspace
=
true
}
arbitrary
=
{
version
=
"1.4.1"
,
features
=
["derive"]
}
libfuzzer-sys
=
"0.4.9"
once_cell
=
{
workspace
=
true
}
serde
=
{
workspace
=
true
}
tokio
=
{
workspace
=
true
,
features
=
["full"]
}
turbo-tasks
=
{
workspace
=
true
}
turbo-tasks-backend
=
{
workspace
=
true
}
turbo-tasks-malloc
=
{
workspace
=
true
}
[build-dependencies]
turbo-tasks-build
=
{
workspace
=
true
}
[[bin]]
name
=
"fuzz_graph"
path
=
"fuzz_targets/graph.rs"
test
=
false
doc
=
false
bench
=
false
[[bin]]
name
=
"afl_graph"
path
=
"afl_targets/graph.rs"
test
=
false
doc
=
false
bench
=
false
turbopack/crates/turbo-tasks-backend/fuzz/afl-in/empty
0 → 100644
View file @
47835e6c
File added
turbopack/crates/turbo-tasks-backend/fuzz/afl_targets/graph.rs
0 → 100644
View file @
47835e6c
#
!
[
feature
(
arbitrary_self_types_pointers
)]
use
afl
::
fuzz
;
use
crate
::
graph
::{
TaskSpec
,
init
,
run
};
#[path
=
"../src/graph.rs"
]
mod
graph
;
// Run with:
// cargo afl build --bin afl_graph
// AFL_AUTORESUME=1 cargo afl fuzz -i turbopack/crates/turbo-tasks-backend/fuzz/afl-in -o
// turbopack/crates/turbo-tasks-backend/fuzz/afl-out -- target/debug/afl_graph
fn
main
()
{
register
();
init
();
fuzz!
(|
data
:
Vec
<
TaskSpec
>
|
{
run
(
data
);
});
}
pub
fn
register
()
{
turbo_tasks
::
register
();
include!
(
concat!
(
env!
(
"OUT_DIR"
),
"/register_afl_graph.rs"
));
}
turbopack/crates/turbo-tasks-backend/fuzz/build.rs
0 → 100644
View file @
47835e6c
use
turbo_tasks_build
::
generate_register
;
fn
main
()
{
generate_register
();
}
turbopack/crates/turbo-tasks-backend/fuzz/fuzz_targets/graph.rs
0 → 100644
View file @
47835e6c
#
!
[
no_main
]
#
!
[
feature
(
arbitrary_self_types_pointers
)]
use
libfuzzer_sys
::
fuzz_target
;
use
crate
::
graph
::{
TaskSpec
,
init
};
#[path
=
"../src/graph.rs"
]
mod
graph
;
// Run with:
// cd turbopack/crates/turbo-tasks-backend
// cargo fuzz run fuzz_graph -- -timeout=3 -print_pcs=1 -print_funcs=999999 -print_final_stats=1
// add --jobs=6 -workers=6 for parallel fuzzing
fuzz_target!
(
init
:
{
register
();
init
();
},
|
data
:
Vec
<
TaskSpec
>
|
{
graph
::
run
(
data
);
});
pub
fn
register
()
{
turbo_tasks
::
register
();
include!
(
concat!
(
env!
(
"OUT_DIR"
),
"/register_fuzz_graph.rs"
));
}
turbopack/crates/turbo-tasks-backend/fuzz/src/graph.rs
0 → 100644
View file @
47835e6c
use
anyhow
::
Result
;
use
arbitrary
::
Arbitrary
;
use
once_cell
::
sync
::
Lazy
;
use
serde
::{
Deserialize
,
Serialize
};
use
turbo_tasks
::{
self
,
NonLocalValue
,
TurboTasks
,
Vc
,
trace
::
TraceRawVcs
};
use
turbo_tasks_malloc
::
TurboMalloc
;
#[derive(
Arbitrary,
Clone,
Debug,
PartialEq,
Eq,
NonLocalValue,
Serialize,
Deserialize,
TraceRawVcs,
)]
pub
struct
TaskReferenceSpec
{
task
:
u16
,
chain
:
u8
,
read
:
bool
,
read_strongly_consistent
:
bool
,
}
#[derive(
Arbitrary,
Clone,
Debug,
PartialEq,
Eq,
NonLocalValue,
Serialize,
Deserialize,
TraceRawVcs,
)]
pub
struct
TaskSpec
{
references
:
Vec
<
TaskReferenceSpec
>
,
children
:
u8
,
}
static
RUNTIME
:
Lazy
<
tokio
::
runtime
::
Runtime
>
=
Lazy
::
new
(||
{
tokio
::
runtime
::
Builder
::
new_multi_thread
()
.enable_all
()
.on_thread_stop
(||
{
TurboMalloc
::
thread_stop
();
})
.build
()
.unwrap
()
});
pub
fn
init
()
{
let
_
=
&*
RUNTIME
;
}
pub
fn
run
(
data
:
Vec
<
TaskSpec
>
)
{
let
mut
data
=
data
;
let
len
=
data
.len
();
if
len
==
0
{
return
;
}
for
(
i
,
task
)
in
data
.iter_mut
()
.enumerate
()
{
for
reference
in
task
.references
.iter_mut
()
{
let
task
=
reference
.task
as
usize
;
if
task
<=
i
{
return
;
}
if
task
>=
len
{
return
;
}
}
}
let
mut
referenced
=
vec!
[
false
;
data
.len
()];
for
task
in
&
data
{
for
reference
in
&
task
.references
{
referenced
[
reference
.task
as
usize
]
=
true
;
}
}
if
!
referenced
.iter
()
.skip
(
1
)
.all
(|
&
x
|
x
)
{
return
;
}
actual_operation
(
data
);
}
fn
actual_operation
(
data
:
Vec
<
TaskSpec
>
)
{
let
tt
=
TurboTasks
::
new
(
turbo_tasks_backend
::
TurboTasksBackend
::
new
(
turbo_tasks_backend
::
BackendOptions
{
storage_mode
:
None
,
small_preallocation
:
true
,
..
Default
::
default
()
},
turbo_tasks_backend
::
noop_backing_storage
(),
));
RUNTIME
.block_on
(
async
{
tt
.run_once
(
async
move
{
let
spec
:
Vc
<
TasksSpec
>
=
Vc
::
cell
(
data
);
run_task
(
spec
,
0
)
.strongly_consistent
()
.await
?
;
Ok
(())
})
.await
})
.unwrap
();
}
#[turbo_tasks
::
value(transparent)]
struct
TasksSpec
(
Vec
<
TaskSpec
>
);
#[turbo_tasks
::
function]
async
fn
run_task_chain
(
spec
:
Vc
<
TasksSpec
>
,
from
:
u16
,
ref_index
:
usize
,
to
:
u16
,
chain
:
u8
,
)
->
Result
<
Vc
<
()
>>
{
if
chain
>
0
{
run_task_chain
(
spec
,
from
,
ref_index
,
to
,
chain
-
1
)
.await
?
;
}
else
{
run_task
(
spec
,
to
)
.await
?
;
}
Ok
(
Vc
::
cell
(()))
}
#[turbo_tasks
::
function]
async
fn
run_task
(
spec
:
Vc
<
TasksSpec
>
,
task_index
:
u16
)
->
Result
<
Vc
<
()
>>
{
let
spec_ref
=
spec
.await
?
;
let
task
=
&
spec_ref
[
task_index
as
usize
];
for
i
in
0
..
task
.children
{
run_task_child
(
task_index
,
i
)
.await
?
;
}
for
(
i
,
reference
)
in
task
.references
.iter
()
.enumerate
()
{
let
call
=
if
reference
.chain
>
0
{
run_task_chain
(
spec
,
task_index
,
i
,
reference
.task
,
reference
.chain
)
}
else
{
run_task
(
spec
,
reference
.task
)
};
if
reference
.read
{
call
.await
?
;
}
if
reference
.read_strongly_consistent
{
call
.strongly_consistent
()
.await
?
;
}
}
Ok
(
Vc
::
cell
(()))
}
#[turbo_tasks
::
function]
async
fn
run_task_child
(
from
:
u16
,
i
:
u8
)
->
Result
<
Vc
<
()
>>
{
let
_
=
from
;
let
_
=
i
;
Ok
(
Vc
::
cell
(()))
}
/// This removes all unused tasks and remaps references to have a continuous range.
#[allow(dead_code,
reason
=
"used to minimize the graph when crash found"
)]
fn
optimize
(
spec
:
Vec
<
TaskSpec
>
)
->
Vec
<
TaskSpec
>
{
let
mut
referenced
=
vec!
[
false
;
spec
.len
()];
for
task
in
&
spec
{
for
reference
in
&
task
.references
{
referenced
[
reference
.task
as
usize
]
=
true
;
}
}
let
mut
new_index
=
vec!
[
usize
::
MAX
;
spec
.len
()];
let
mut
index
=
0
;
for
i
in
0
..
spec
.len
()
{
if
referenced
[
i
]
{
new_index
[
i
]
=
index
;
index
+=
1
;
}
}
let
mut
new_spec
=
vec!
[];
for
(
i
,
task
)
in
spec
.iter
()
.enumerate
()
{
if
referenced
[
i
]
{
let
mut
new_task
=
task
.clone
();
for
reference
in
&
mut
new_task
.references
{
reference
.task
=
new_index
[
reference
.task
as
usize
]
as
u16
;
}
new_spec
.push
(
new_task
);
}
}
new_spec
}
turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
View file @
47835e6c
...
...
@@ -138,6 +138,9 @@ pub struct BackendOptions {
/// Enables the backing storage.
pub
storage_mode
:
Option
<
StorageMode
>
,
/// Avoid big preallocations for faster startup. Should only be used for testing purposes.
pub
small_preallocation
:
bool
,
}
impl
Default
for
BackendOptions
{
...
...
@@ -147,6 +150,7 @@ impl Default for BackendOptions {
children_tracking
:
true
,
active_tracking
:
true
,
storage_mode
:
Some
(
StorageMode
::
ReadWrite
),
small_preallocation
:
false
,
}
}
}
...
...
@@ -224,6 +228,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
if
!
options
.dependency_tracking
{
options
.active_tracking
=
false
;
}
let
small_preallocation
=
options
.small_preallocation
;
Self
{
options
,
start_time
:
Instant
::
now
(),
...
...
@@ -243,7 +248,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
persisted_task_cache_log
:
need_log
.then
(||
Sharded
::
new
(
shard_amount
)),
task_cache
:
BiMap
::
new
(),
transient_tasks
:
FxDashMap
::
default
(),
storage
:
Storage
::
new
(),
storage
:
Storage
::
new
(
small_preallocation
),
in_progress_operations
:
AtomicUsize
::
new
(
0
),
snapshot_request
:
Mutex
::
new
(
SnapshotRequest
::
new
()),
operations_suspended
:
Condvar
::
new
(),
...
...
turbopack/crates/turbo-tasks-backend/src/backend/storage.rs
View file @
47835e6c
...
...
@@ -612,18 +612,27 @@ pub struct Storage {
}
impl
Storage
{
pub
fn
new
()
->
Self
{
pub
fn
new
(
small_preallocation
:
bool
)
->
Self
{
let
map_capacity
:
usize
=
if
small_preallocation
{
1024
}
else
{
1024
*
1024
};
let
modified_capacity
:
usize
=
if
small_preallocation
{
0
}
else
{
1024
};
let
shard_factor
:
usize
=
if
small_preallocation
{
4
}
else
{
64
};
let
shard_amount
=
(
available_parallelism
()
.map_or
(
4
,
|
v
|
v
.get
())
*
64
)
.next_power_of_two
();
(
available_parallelism
()
.map_or
(
4
,
|
v
|
v
.get
())
*
shard_factor
)
.next_power_of_two
();
Self
{
snapshot_mode
:
AtomicBool
::
new
(
false
),
modified
:
FxDashMap
::
with_capacity_and_hasher_and_shard_amount
(
1024
,
modified_capacity
,
Default
::
default
(),
shard_amount
,
),
map
:
FxDashMap
::
with_capacity_and_hasher_and_shard_amount
(
1024
*
1024
,
map_capacity
,
Default
::
default
(),
shard_amount
,
),
...
...
turbopack/crates/turbo-tasks-backend/tests/bug.rs
0 → 100644
View file @
47835e6c
#
!
[
feature
(
arbitrary_self_types
)]
#
!
[
feature
(
arbitrary_self_types_pointers
)]
#
!
[
allow
(
clippy
::
needless_return
)]
// tokio macro-generated code doesn't respect this
use
anyhow
::
Result
;
use
serde
::{
Deserialize
,
Serialize
};
use
turbo_tasks
::{
NonLocalValue
,
Vc
,
trace
::
TraceRawVcs
};
use
turbo_tasks_testing
::{
Registration
,
register
,
run
};
static
REGISTRATION
:
Registration
=
register!
();
#[derive(Debug,
Clone,
PartialEq,
Eq,
NonLocalValue,
Serialize,
Deserialize,
TraceRawVcs)]
struct
TaskReferenceSpec
{
task
:
u16
,
read
:
bool
,
read_strongly_consistent
:
bool
,
}
#[derive(Debug,
Clone,
PartialEq,
Eq,
NonLocalValue,
Serialize,
Deserialize,
TraceRawVcs)]
struct
TaskSpec
{
references
:
Vec
<
TaskReferenceSpec
>
,
}
#[turbo_tasks
::
value(transparent)]
struct
TasksSpec
(
Vec
<
TaskSpec
>
);
#[tokio
::
test]
async
fn
graph_bug
()
{
// see https://github.com/vercel/next.js/pull/79451
run
(
&
REGISTRATION
,
||
async
{
let
spec
=
vec!
[
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
3
,
read
:
false
,
read_strongly_consistent
:
true
,
},
TaskReferenceSpec
{
task
:
1
,
read
:
true
,
read_strongly_consistent
:
false
,
},
TaskReferenceSpec
{
task
:
12
,
read
:
false
,
read_strongly_consistent
:
true
,
},
],
},
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
2
,
read
:
true
,
read_strongly_consistent
:
true
,
}],
},
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
4
,
read
:
false
,
read_strongly_consistent
:
false
,
}],
},
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
6
,
read
:
false
,
read_strongly_consistent
:
false
,
}],
},
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
5
,
read
:
false
,
read_strongly_consistent
:
false
,
},
TaskReferenceSpec
{
task
:
13
,
read
:
false
,
read_strongly_consistent
:
false
,
},
],
},
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
11
,
read
:
false
,
read_strongly_consistent
:
true
,
},
TaskReferenceSpec
{
task
:
14
,
read
:
false
,
read_strongly_consistent
:
false
,
},
TaskReferenceSpec
{
task
:
7
,
read
:
false
,
read_strongly_consistent
:
false
,
},
TaskReferenceSpec
{
task
:
8
,
read
:
false
,
read_strongly_consistent
:
false
,
},
],
},
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
9
,
read
:
false
,
read_strongly_consistent
:
false
,
}],
},
TaskSpec
{
references
:
vec!
[]
},
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
12
,
read
:
false
,
read_strongly_consistent
:
false
,
},
TaskReferenceSpec
{
task
:
11
,
read
:
false
,
read_strongly_consistent
:
false
,
},
],
},
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
10
,
read
:
false
,
read_strongly_consistent
:
false
,
}],
},
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
12
,
read
:
false
,
read_strongly_consistent
:
false
,
}],
},
TaskSpec
{
references
:
vec!
[]
},
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
14
,
read
:
false
,
read_strongly_consistent
:
false
,
}],
},
TaskSpec
{
references
:
vec!
[]
},
TaskSpec
{
references
:
vec!
[
TaskReferenceSpec
{
task
:
16
,
read
:
false
,
read_strongly_consistent
:
true
,
},
TaskReferenceSpec
{
task
:
15
,
read
:
false
,
read_strongly_consistent
:
true
,
},
],
},
TaskSpec
{
references
:
vec!
[]
},
TaskSpec
{
references
:
vec!
[]
},
];
let
spec
:
Vc
<
TasksSpec
>
=
Vc
::
cell
(
spec
);
run_task
(
spec
,
0
)
.await
?
;
anyhow
::
Ok
(())
})
.await
.unwrap
()
}
#[turbo_tasks
::
function]
async
fn
run_task
(
spec
:
Vc
<
TasksSpec
>
,
task
:
u16
)
->
Result
<
Vc
<
()
>>
{
let
spec_ref
=
spec
.await
?
;
let
task
=
&
spec_ref
[
task
as
usize
];
for
reference
in
&
task
.references
{
let
call
=
run_task
(
spec
,
reference
.task
);
if
reference
.read
{
call
.await
?
;
}
if
reference
.read_strongly_consistent
{
call
.strongly_consistent
()
.await
?
;
}
}
Ok
(
Vc
::
cell
(()))
}
turbopack/crates/turbo-tasks-build/src/lib.rs
View file @
47835e6c
...
...
@@ -11,8 +11,8 @@ use glob::glob;
use
quote
::
ToTokens
;
use
rustc_hash
::{
FxHashMap
,
FxHashSet
};
use
syn
::{
Attribute
,
Ident
,
Item
,
ItemEnum
,
ItemFn
,
ItemImpl
,
ItemMacro
,
ItemMod
,
ItemStruct
,
ItemTrai
t
,
TraitItem
,
TraitItemFn
,
parse_quote
,
Attribute
,
Expr
,
Ident
,
Item
,
ItemEnum
,
ItemFn
,
ItemImpl
,
ItemMacro
,
ItemMod
,
ItemStruc
t
,
ItemTrait
,
Lit
,
Meta
,
TraitItem
,
TraitItemFn
,
parse_quote
,
};
use
turbo_tasks_macros_shared
::{
GenericTypeInput
,
PrimitiveInput
,
get_impl_function_ident
,
get_native_function_ident
,
...
...
@@ -34,6 +34,8 @@ pub fn generate_register() {
let
src_dir
=
crate_dir
.join
(
"src"
);
let
examples_dir
=
crate_dir
.join
(
"examples"
);
let
tests_dir
=
crate_dir
.join
(
"tests"
);
let
fuzz_dir
=
crate_dir
.join
(
"fuzz_targets"
);
let
afl_dir
=
crate_dir
.join
(
"afl_targets"
);
let
benches_dir
=
crate_dir
.join
(
"benches"
);
let
cargo_lock_path
=
workspace_dir
.join
(
"Cargo.lock"
);
...
...
@@ -80,6 +82,34 @@ pub fn generate_register() {
}
}
if
afl_dir
.exists
()
{
for
item
in
read_dir
(
afl_dir
)
.unwrap
()
{
let
item
=
item
.unwrap
();
let
file_type
=
&
item
.file_type
()
.unwrap
();
if
file_type
.is_file
()
||
file_type
.is_symlink
()
{
let
name
=
item
.file_name
();
let
name
=
name
.to_string_lossy
();
if
name
.ends_with
(
".rs"
)
{
entries
.push
((
format!
(
"register_afl_{name}"
),
item
.path
()));
}
}
}
}
if
fuzz_dir
.exists
()
{
for
item
in
read_dir
(
fuzz_dir
)
.unwrap
()
{
let
item
=
item
.unwrap
();
let
file_type
=
&
item
.file_type
()
.unwrap
();
if
file_type
.is_file
()
||
file_type
.is_symlink
()
{
let
name
=
item
.file_name
();
let
name
=
name
.to_string_lossy
();
if
name
.ends_with
(
".rs"
)
{
entries
.push
((
format!
(
"register_fuzz_{name}"
),
item
.path
()));
}
}
}
}
if
benches_dir
.exists
()
{
let
bench_mod
=
benches_dir
.join
(
"mod.rs"
);
if
bench_mod
.is_file
()
||
bench_mod
.is_symlink
()
{
...
...
@@ -340,21 +370,46 @@ impl RegisterContext<'_> {
self
.mod_path
=
parent_mod_path
;
}
else
{
let
parent_file_path
=
self
.file_path
.parent
()
.unwrap
();
let
direct
=
parent_file_path
.join
(
format!
(
"{child_mod_name}.rs"
));
if
direct
.exists
()
{
if
let
Some
(
path
)
=
mod_item
.attrs
.iter
()
.find_map
(|
attr
|
{
let
Meta
::
NameValue
(
pair
)
=
&
attr
.meta
else
{
return
None
;
};
if
!
pair
.path
.is_ident
(
"path"
)
{
return
None
;
}
let
Expr
::
Lit
(
lit
)
=
&
pair
.value
else
{
return
None
;
};
let
Lit
::
Str
(
str
)
=
&
lit
.lit
else
{
return
None
;
};
let
path
=
str
.value
();
let
path
=
path
.replace
(
'/'
,
&
format!
(
"{PATH_SEP}"
));
let
path
=
parent_file_path
.join
(
path
);
Some
(
path
)
})
{
self
.queue
.push
(
QueueEntry
{
file_path
:
direct
,
file_path
:
path
,
mod_path
:
child_mod_path
,
attributes
:
self
.attributes
.clone
(),
});
}
else
{
let
nested
=
parent_file_path
.join
(
&
child_mod_name
)
.join
(
"mod.rs"
);
if
nested
.exists
()
{
let
direct
=
parent_file_path
.join
(
format!
(
"{child_mod_name}.rs"
)
);
if
direct
.exists
()
{
self
.queue
.push
(
QueueEntry
{
file_path
:
nested
,
file_path
:
direct
,
mod_path
:
child_mod_path
,
attributes
:
self
.attributes
.clone
(),
});
}
else
{
let
nested
=
parent_file_path
.join
(
&
child_mod_name
)
.join
(
"mod.rs"
);
if
nested
.exists
()
{
self
.queue
.push
(
QueueEntry
{
file_path
:
nested
,
mod_path
:
child_mod_path
,
attributes
:
self
.attributes
.clone
(),
});
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment