-
Notifications
You must be signed in to change notification settings - Fork 29
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
Middle-ground vendoring option using a local registry #46
Open
cormacrelf
wants to merge
9
commits into
facebookincubator:main
Choose a base branch
from
cormacrelf:feature/local-registry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Middle-ground vendoring option using a local registry #46
cormacrelf
wants to merge
9
commits into
facebookincubator:main
from
cormacrelf:feature/local-registry
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
facebook-github-bot
added
the
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
label
May 22, 2024
And here is an `extract_archive` rule based on prelude's `http_archive` that makes all this work.def _tar_strip_prefix_flags(strip_prefix: [str, None]) -> list[str]:
if strip_prefix:
# count nonempty path components in the prefix
count = len(filter(lambda c: c != "", strip_prefix.split("/")))
return ["--strip-components=" + str(count), strip_prefix]
return []
def _unarchive_cmd(
# ext_type: str,
# exec_is_windows: bool,
archive: Artifact,
strip_prefix: [str, None]) -> (cmd_args, bool):
unarchive_cmd = cmd_args(
"tar",
"-xzf",
archive,
_tar_strip_prefix_flags(strip_prefix),
)
return unarchive_cmd, False
def _extract_archive_impl(ctx: AnalysisContext) -> list[Provider]:
archive = ctx.attrs.src
# no need to prefer local; this is not a downloaded object. unlike http_archive
prefer_local = False
unarchive_cmd, needs_strip_prefix = _unarchive_cmd(archive, ctx.attrs.strip_prefix)
exec_is_windows = False
output_name = ctx.label.name
output = ctx.actions.declare_output(output_name, dir = True)
script_output = ctx.actions.declare_output(output_name + "_tmp", dir = True) if needs_strip_prefix else output
if exec_is_windows:
ext = "bat"
mkdir = "md {}"
interpreter = []
else:
ext = "sh"
mkdir = "mkdir -p {}"
interpreter = ["/bin/sh"]
exclude_flags = []
script, _ = ctx.actions.write(
"unpack.{}".format(ext),
[
cmd_args(script_output, format = mkdir),
cmd_args(script_output, format = "cd {}"),
cmd_args([unarchive_cmd] + exclude_flags, delimiter = " ").relative_to(script_output),
],
is_executable = True,
allow_args = True,
)
exclude_hidden = []
ctx.actions.run(
cmd_args(interpreter + [script]).hidden(exclude_hidden + [archive, script_output.as_output()]),
category = "extract_archive",
prefer_local = prefer_local,
)
if needs_strip_prefix:
ctx.actions.copy_dir(output.as_output(), script_output.project(ctx.attrs.strip_prefix))
return [DefaultInfo(
default_output = output,
sub_targets = {
path: [DefaultInfo(default_output = output.project(path))]
for path in ctx.attrs.sub_targets
},
)]
extract_archive = rule(
impl = _extract_archive_impl,
attrs = {
"src": attrs.source(),
"strip_prefix": attrs.option(attrs.string(), default = None),
"sub_targets": attrs.list(attrs.string(), default = [], doc = """
A list of filepaths within the archive to be made accessible as sub-targets.
For example if we have an http_archive with `name = "archive"` and
`sub_targets = ["src/lib.rs"]`, then other targets would be able to refer
to that file as `":archive[src/lib.rs]"`.
"""),
},
) |
cormacrelf
force-pushed
the
feature/local-registry
branch
from
May 22, 2024 12:35
2eb5ad4
to
d8c14c7
Compare
cormacrelf
force-pushed
the
feature/local-registry
branch
from
May 22, 2024 12:40
d8c14c7
to
e1d2c53
Compare
cormacrelf
force-pushed
the
feature/local-registry
branch
from
September 4, 2024 07:52
cb858a3
to
a7b0188
Compare
@cormacrelf I think your analysis is on point; there is a gap here that the tarballs fill nicely. |
Maybe @jsgf? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem is a goldilocks one.
vendor = false
is quick & easy to manage deps & buckify, but pretty bad day to day.reindeer buckify
takes 2 seconds or so. Pretty convenient.[vendor] ...
is slow to manage deps & buckify.vendor
directory of 1000 crates, 1.2 GB, 50k source files. Mostly from dupes of the windows crates which can't be pinned to one single version etc.reindeer vendor
takes 35 secondsreindeer buckify
takes 20 secondsgit status
takes 150msI think we need a solution for the middle ground:
vendor = "local-registry"
, using https://github.com/dhovart/cargo-local-registryreindeer vendor
ultimately just writes a bunch of .crate files into vendor/, which are just gzipped tarballswindows-0.48.0.crate
is just a blob. Your diffs are much simpler when you modify deps. Etc.strip_prefix
andsub_targets
support, but prelude'sextract_archive
could probably have that added.)Outcomes:
although doesn't handle cargo).package = { git = "..." }
deps yetreindeer vendor
andreindeer buckify
both take 2 secondsgit status
takes 20mswindows-0.48.0.crate
on linux, and you only pay for what you build.Problems:
cargo
crate it would be maybe a 2-file crate. And we could use it as a library.index
folder (nestedab/ ac/ ah/ ...
folders) might be a little bit annoying if you're making concurrent edits on different branches. But you can always regenerate.