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

Sync hook for downloading rust-toolchain-aux. #27749

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

szilardszaloki
Copy link
Collaborator

@szilardszaloki szilardszaloki commented Feb 20, 2025

Resolves brave/brave-browser#44132.

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@github-actions github-actions bot added CI/run-audit-deps Check for known npm/cargo vulnerabilities (audit_deps) CI/storybook-url Deploy storybook and provide a unique URL for each build labels Feb 20, 2025
@szilardszaloki szilardszaloki added CI/run-linux-arm64 Run CI builds for Linux arm64 CI/run-windows-arm64 Run CI builds for Windows arm64 CI/run-windows-x86 Run CI builds for Windows x86 CI/run-macos-x64 Run CI builds for macOS x64 labels Feb 20, 2025
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Base automatically changed from szilard/44131-build-rust-toolchain-aux-windows to master February 20, 2025 21:47
@szilardszaloki szilardszaloki changed the base branch from master to szilard/44140-fix-arcname February 21, 2025 00:27
@szilardszaloki szilardszaloki changed the base branch from szilard/44140-fix-arcname to master February 21, 2025 00:31
@szilardszaloki szilardszaloki changed the base branch from master to szilard/44140-fix-arcname February 21, 2025 00:37
@szilardszaloki szilardszaloki force-pushed the szilard/44132-sync-hook-for-downloading-rust-toolchain-aux branch from 372c951 to 3ddbebf Compare February 21, 2025 00:38
@szilardszaloki szilardszaloki changed the base branch from szilard/44140-fix-arcname to master February 21, 2025 07:01
@szilardszaloki szilardszaloki force-pushed the szilard/44132-sync-hook-for-downloading-rust-toolchain-aux branch from 3ddbebf to 37daed8 Compare February 21, 2025 15:48
@szilardszaloki szilardszaloki removed CI/run-linux-arm64 Run CI builds for Linux arm64 CI/run-windows-arm64 Run CI builds for Windows arm64 CI/run-windows-x86 Run CI builds for Windows x86 CI/run-macos-x64 Run CI builds for macOS x64 labels Feb 21, 2025
@szilardszaloki szilardszaloki force-pushed the szilard/44132-sync-hook-for-downloading-rust-toolchain-aux branch from 37daed8 to 868486d Compare February 21, 2025 19:07
@szilardszaloki szilardszaloki added CI/skip Do not run CI builds (except noplatform) CI/run-linux-arm64 Run CI builds for Linux arm64 CI/run-windows-arm64 Run CI builds for Windows arm64 CI/run-windows-x86 Run CI builds for Windows x86 CI/run-macos-x64 Run CI builds for macOS x64 and removed CI/skip Do not run CI builds (except noplatform) labels Feb 21, 2025
@szilardszaloki szilardszaloki force-pushed the szilard/44132-sync-hook-for-downloading-rust-toolchain-aux branch 3 times, most recently from f25ddea to 7ca0bae Compare February 24, 2025 22:22
@szilardszaloki szilardszaloki marked this pull request as ready for review February 24, 2025 22:22
@szilardszaloki szilardszaloki requested review from a team as code owners February 24, 2025 22:22
@szilardszaloki szilardszaloki removed CI/run-linux-arm64 Run CI builds for Linux arm64 CI/run-windows-arm64 Run CI builds for Windows arm64 CI/run-windows-x86 Run CI builds for Windows x86 CI/run-macos-x64 Run CI builds for macOS x64 labels Feb 24, 2025

with tempfile.TemporaryFile() as temp_file:
try:
deps.DownloadUrl(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm run sync should not download this if the required version is already unpacked.
Will this be a no-op if the required version is already downloaded and unpacked?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we don't store the version of these artifacts — they are always in sync with whatever Rust and Clang revisions Chromium has in tools/rust/update_rust.py and tools/clang/scripts/update.py, respectively. We can also bundle src/third_party/rust-toolchain/VERSION with them, which will make it possible to only perform the download when necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with any approach, just make sure this is no-op if the required file is already downloaded. You can use sha256 or git commit or something else. You can look into existing deps and how they handle this.

"to build the required Rust aux package.")
raise

with temporary_directory() as temp_dir:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be replaced with with tempfile.TemporaryDirectory() as temp_dir:

make sure to unpack the content into the source tree, NOT into TMP as TMP most likely will have AV protection enabled (on Windows at least), which may trigger it randomly.

but you should just use deps.DownloadAndUnpack.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AV thing is a good point, but the same applies to the tempfile.NamedTemporaryFile() call in deps.DownloadAndUnpack(), no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AV thing is a good point, but the same applies to the tempfile.NamedTemporaryFile() call in deps.DownloadAndUnpack(), no?

that is true, but for some reason Chromium is fine with that (in their deps downloader impl they download to tmp).

My guess is the risk of AV triggering on an archive access is much lower rather than writing a real executable on disk when unpacking.

raise

with temporary_directory() as temp_dir:
file.seek(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls consider handling *.tar.xz in deps.DownloadAndUnpack instead of this file juggling here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main concern with DownloadAndUnpack() is not that it doesn't handle XZ files, but that it gets rid of the temp file it downloads the archive into after extracting it (which we want to keep). It's an outdated version of Chromium's DownloadAndUnpack() in tools/clang/scripts/update.py by the way.

Also, a minimal file juggling is necessary, as the files in the package go to different places.

@szilardszaloki szilardszaloki force-pushed the szilard/44132-sync-hook-for-downloading-rust-toolchain-aux branch from 1041cb1 to 7f7159c Compare February 27, 2025 17:59
@szilardszaloki szilardszaloki force-pushed the szilard/44132-sync-hook-for-downloading-rust-toolchain-aux branch from 7f7159c to c0d6cac Compare February 27, 2025 19:45
deps.DownloadAndUnpack(
f'{deps_config.DEPS_PACKAGES_URL}/rust-toolchain-aux/{build_rust_toolchain_aux.package_name()}',
temp_dir,
output_file=PACKAGE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, you can keep the whole archive and make some changes to DownloadAndUnpack, but consider storing a simple text file like ${RUST_TOOLCHAIN}/.brave_toolchain_aux_package with the downloaded/unpacked package and read/write it from you script to detect if you need the update.

script/deps.py Outdated
else:
t = tarfile.open(tmp_file.name, mode='r:gz')
t = tarfile.open(file.name, mode='r:*')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is cool, I didn't know about this mode.

@szilardszaloki szilardszaloki force-pushed the szilard/44132-sync-hook-for-downloading-rust-toolchain-aux branch from a85b4ae to d6a2653 Compare February 28, 2025 22:42
print(f'Skipping {Path(__file__).stem}')
return

with tempfile.TemporaryDirectory(dir=RUST_TOOLCHAIN) as temp_dir:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this may left temp directories in a tree if the script was aborted via Ctrl+C.

but it's fine for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/run-audit-deps Check for known npm/cargo vulnerabilities (audit_deps) CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement sync hook for downloading our rust_toolchain_aux package.
4 participants