Status: published as https://cs.opensource.google/fuchsia/fuchsia/+/main:build/rust/docs/2021-edition-migration.md
rustc_artifact.gni
to support new edition.--force-warn=rust-2021-compatibility
to args.fx clippy --all --raw > lints.json
(make sure to add repos --with //bundles:kitchen_sink --with //bundles/buildbot:core
)fx shush lints.json --lint rust-2021-compatibility fix
(after building shush fx build host-tools/shush
)
jq '.[] | select(.src[0] | startswith("..")) | .original' out/edition_migration/clippy_target_mapping.json -r | sed 's/(.*$//' | sort -u > /tmp/clippy_targets.txt
edition = 2021
for each of them in BUILD.gn.go run cmd/examples/rust_migration "$FUCHSIA_DIR" /tmp/clippy_targets.txt | tee /tmp/migration_log.txt
edition = 2018
and make edition
requirededition
to default to 2021 instead of being required. Or not.The rustfmt.toml in our root directory needs to be updated to 2021 edition (even though that might be a no-op?)
jiri update -gc -v
# add `--force-warn=rust-2021-compatibility`
vim ./build/rust/clippy.gni
git commit -a -m "throwaway"
fx set core.x64 --with //bundles:kitchen_sink --with //bundles/buildbot:core
fx clippy --all --raw > lints.json
fx build host-tools/shush
fx shush lints.json --lint rust-2021-compatibility fix
# Pending https://fxbug.dev/101439 fix
git restore src/settings/service
git commit -a -m "[rust] Edition 2021 fixes"
jq '.[] | select(.src[0] | startswith("..")) | .original' out/default/clippy_target_mapping.json -r | sed 's/(.*$//' | sort -u > /tmp/clippy_targets.txt
cd ~/infra/fuchsia/infra/codifier
jiri update -gc -v
go run cmd/examples/rust_migration/main.go "$FUCHSIA_DIR" /tmp/clippy_targets.txt | tee /tmp/migration_log.txt
git restore src/settings/service
At this point, manual fixups are required:
$ grep "couldn't find" /tmp/migration_log.txt| grep -v //src/tests/fidl/source_compatibility/
couldn't find //src/developer/ffx/daemon/protocols:ffx_daemon_protocols_lib
couldn't find //src/developer/ffx:ffx
couldn't find //src/lib/fuchsia-cxx/examples/basic:example_blobstore_rustc_library
couldn't find //src/storage/fuchsia-fatfs:fatfs
couldn't find //src/storage/fxfs:fxfs
couldn't find //src/sys/pkg/lib/fuchsia-pkg:lib_test
Manually add edition = "2021"
to each of the targets in ^
rust_cxx_ffi_library("example_blobstore")
and ffx_protocols("ffx_daemon_protocols")
hardcodes edition 2018 (and doesnt forward from invocations) so we left it alone
fx gen
fails due to component_manager (another template which sets edition itself). This time we updated the template definition to the new edition.
fx gen
succeeds
2015 edition opt-outs:
git restore --source HEAD^ src/lib/mundane/
git restore --source HEAD^ third_party/rust_crates/compat/rustyline
git -C third_party/rust_crates/mirrors/rustyline reset --hard
git -C third_party/rust_crates/mirrors/quiche reset --hard
git -C third_party/alacritty reset --hard
fx build
(fails due to TryInto)
git fetch https://fuchsia.googlesource.com/fuchsia refs/changes/14/684214/5 && git cherry-pick FETCH_HEAD
fx build
(works this time)
Set up
jiri update -gc -v
# go migration tool, not needed once it lands
cd ~/infra/fuchsia/infra && git fetch https://fuchsia.googlesource.com/infra/infra refs/changes/44/683144/2 && git cherry-pick FETCH_HEAD
# original_target_name patch, not needed once it lands
cd ~/fuchsia && git fetch https://fuchsia.googlesource.com/fuchsia refs/changes/68/680568/9 && git cherry-pick FETCH_HEAD
fx --dir=out/edition_migration set core.x64 --with //vendor/google/bundles:kitchen_sink --with //vendor/google/bundles/buildbot:core
$ git -C integration rev-parse HEAD
6f840862b6f73f9f49a30b27eab835959b2cd6d8
Do step 2 from above
git commit -am 'throwaway commit'
fx clippy --all --raw | tee /tmp/lints.json | jq -r '.rendered'
$ fx build host-tools/shush
$ fx shush /tmp/lints.json --lint rust-2021-compatibility fix
1 fixes in src/settings/service/src/tests/fakes/base.rs
1 fixes in src/sys/run_test_suite/src/lib.rs
1 fixes in src/connectivity/wlan/wlancfg/src/mode_management/iface_manager.rs
1 fixes in src/sys/test_manager/debug_data/src/iterator.rs
1 fixes in src/settings/service/src/agent/inspect/setting_values.rs
1 fixes in src/connectivity/lib/ping/src/fuchsia.rs
1 fixes in src/sys/pkg/tests/omaha-client/src/lib.rs
1 fixes in src/sys/test_manager/src/running_suite.rs
1 fixes in src/session/bin/element_manager/src/element_manager.rs
2 fixes in src/modular/tests/basemgr_v2_test.rs
2 fixes in src/testing/sl4f/src/weave/facade.rs
2 fixes in src/lib/storage/vfs/rust/src/filesystem/simple.rs
1 fixes in src/sys/pkg/tests/system-updater/src/lib.rs
1 fixes in src/settings/service/src/migration.rs
1 fixes in src/diagnostics/detect/integration/integration_test.rs
1 fixes in third_party/rust_crates/mirrors/rustyline/src/tty/unix.rs
1 fixes in src/settings/service/src/tests/agent_tests.rs
2 fixes in src/lib/storage/vfs/rust/src/filesystem.rs
3 fixes in src/connectivity/bluetooth/tools/bt-cli/src/main.rs
8 fixes in src/connectivity/wlan/lib/common/rust/src/test_utils/mod.rs
2 fixes in src/sys/test_manager/src/debug_data_server.rs
1 fixes in src/settings/service/src/agent/inspect/usage_counts.rs
1 fixes in src/sys/pkg/bin/omaha-client/src/policy.rs
2 fixes in src/settings/service/src/tests/setting_handler_tests.rs
1 fixes in examples/diagnostics/inspect/codelab/rust/part_2/src/reverser.rs
1 fixes in src/lib/fuchsia-component-test/src/local_component_runner.rs
1 fixes in src/diagnostics/validator/inspect/lib/rust/src/main.rs
1 fixes in src/settings/service/src/tests/event_tests.rs
1 fixes in src/settings/service/src/tests/setting_proxy_tests.rs
1 fixes in src/settings/service/src/tests/environment_tests.rs
1 fixes in src/ui/tools/tiles/flatland/src/main.rs
1 fixes in src/sys/pkg/tests/pkg-local-mirror/src/lib.rs
1 fixes in src/settings/service/src/policy/policy_handler.rs
1 fixes in src/settings/service/src/agent/authority.rs
1 fixes in src/connectivity/network/tests/integration/sys/src/lib.rs
1 fixes in src/connectivity/lib/packet-formats/src/tcp.rs
1 fixes in src/settings/service/src/tests/resource_monitor_tests.rs
1 fixes in src/settings/service/src/job/manager.rs
2 fixes in src/lib/storage/vfs/rust/src/directory/mutable/connection/io1.rs
1 fixes in examples/diagnostics/inspect/codelab/rust/part_5/src/reverser.rs
1 fixes in src/lib/fuchsia-component-test/tests/src/lib.rs
1 fixes in src/settings/service/src/handler/setting_handler.rs
5 fixes in src/connectivity/bluetooth/profiles/tests/bt-avrcp-integration-tests/src/main.rs
1 fixes in examples/diagnostics/inspect/codelab/rust/part_3/src/reverser.rs
1 fixes in src/connectivity/bluetooth/profiles/bt-a2dp/src/sink_task.rs
1 fixes in src/settings/service/src/agent/inspect/policy_values.rs
1 fixes in src/modular/bin/basemgr/basemgr_v1_to_v2_test_realm.rs
1 fixes in src/sys/pkg/tests/system-update-checker/src/lib.rs
1 fixes in src/sys/test_runners/inspect/tests/main.rs
1 fixes in src/connectivity/lowpan/drivers/lowpan-ot-driver/src/driver/srp_proxy/discovery_proxy.rs
1 fixes in src/lib/storage/vfs/rust/src/file/connection/io1.rs
1 fixes in src/settings/service/src/agent/inspect/setting_proxy.rs
1 fixes in src/connectivity/network/netstack3/src/bindings/interfaces_watcher.rs
1 fixes in src/settings/service/src/agent/earcons/agent.rs
1 fixes in examples/diagnostics/inspect/codelab/rust/part_4/src/reverser.rs
1 fixes in src/sys/time/timekeeper_integration/tests/lib/lib.rs
1 fixes in src/sys/component_manager/tests/binder/src/looper.rs
Do step 5 from above
cd ~/infra/fuchsia/infra/codifier
# First edit the following go file with the correct paths
go run cmd/examples/rust_migration.go | tee /tmp/migration_log.txt
$ grep "couldn't find" /tmp/migration_log.txt| grep -v //src/tests/fidl/source_compatibility/
couldn't find //src/developer/ffx/daemon/protocols:ffx_daemon_protocols_lib
couldn't find //src/developer/ffx:ffx
couldn't find //src/developer/ffx:ffx_bin_unversioned
couldn't find //src/lib/fuchsia-cxx/examples/basic:example_blobstore_rustc_library
couldn't find //src/storage/fuchsia-fatfs:fatfs
couldn't find //src/storage/fxfs:fxfs
couldn't find //src/sys/pkg/lib/fuchsia-pkg:lib_test
$ git status src/tests/fidl/source_compatibility
HEAD detached from 7495376c68e
nothing to commit, working tree clean
Do step 7 from above
Manually fix each of ^ by modifying the respective BUILD.gn files.
Not migrated:
fx format-code
fx gen
Extra fixes:
2015 edition opt-outs:
git restore --source HEAD^ src/lib/mundane/
git restore --source HEAD^ third_party/rust_crates/compat/rustyline
git -C third_party/rust_crates/mirrors/rustyline reset --hard
git -C third_party/rust_crates/mirrors/quiche reset --hard
git -C third_party/alacritty reset --hard
cobalt: https://fxrev.dev/683147
fuchsia: https://fxrev.dev/684212