From ff8c76828a11f3351c0a0f99217969600f6f31b3 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Sun, 6 Aug 2023 17:50:00 -0500 Subject: [PATCH] lib: add BUILD files The `grammar` macro from `pest_derive` doesn't actually interpret the given file as relative in our case, so we have to give it the fully qualified relative path which exists in the `buck-out/` dir. Signed-off-by: Austin Seipp --- BUILD | 1 + lib/BUILD | 115 ++++++++++++++++++++++++++++++++++++++ lib/Cargo.toml | 2 + lib/PACKAGE | 5 ++ lib/src/fileset_parser.rs | 6 ++ lib/src/revset_parser.rs | 6 ++ 6 files changed, 135 insertions(+) create mode 100644 lib/BUILD create mode 100644 lib/PACKAGE diff --git a/BUILD b/BUILD index a256decc88..bb0aee3ec2 100644 --- a/BUILD +++ b/BUILD @@ -3,6 +3,7 @@ alias(name = name, actual = actual) for (name, actual) in [ # (top-level name, fully-qualified target name) + ("jj-lib", "//lib:lib"), ("gen-protos", "//lib/gen-protos:gen-protos"), ("proc-macros", "//lib/proc-macros:proc-macros"), ] diff --git a/lib/BUILD b/lib/BUILD new file mode 100644 index 0000000000..3a23cd3d53 --- /dev/null +++ b/lib/BUILD @@ -0,0 +1,115 @@ + +load("//buck/shims/jj.bzl", "jj") + +[ + # set an alias for 'lib' which is the default for this package, and jj-lib + # which other crates may set dependencies on. defaults to the full build + alias( + name = name, + actual = ':jj-lib-full', + ) for name in [ 'lib', 'jj-lib' ] +] + +filegroup( + name = 'protos.pb', + srcs = glob(['src/protos/*.proto']), + visibility = [ '//lib/...' ], +) + +# extra dependencies for the full build of jj-lib +FULL_DEPS = [ + 'third-party//rust:git2', + 'third-party//rust:gix', + 'third-party//rust:watchman_client', +] + +# these deps are shared between all versions +# of jj-lib. filter out FULL_DEPS from this list +COMMON_DEPS = filter(lambda x: x not in FULL_DEPS, [ + # CARGO-SYNC-START: dependencies + '//lib/proc-macros:jj-lib-proc-macros', + 'third-party//rust:async-trait', + 'third-party//rust:backoff', + 'third-party//rust:blake2', + 'third-party//rust:bytes', + 'third-party//rust:chrono', + 'third-party//rust:config', + 'third-party//rust:digest', + 'third-party//rust:either', + 'third-party//rust:futures', + 'third-party//rust:git2', + 'third-party//rust:gix', + 'third-party//rust:glob', + 'third-party//rust:hex', + 'third-party//rust:ignore', + 'third-party//rust:itertools', + 'third-party//rust:maplit', + 'third-party//rust:once_cell', + 'third-party//rust:pest', + 'third-party//rust:pest_derive', + 'third-party//rust:pollster', + 'third-party//rust:prost', + 'third-party//rust:rand', + 'third-party//rust:rand_chacha', + 'third-party//rust:rayon', + 'third-party//rust:ref-cast', + 'third-party//rust:regex', + 'third-party//rust:serde', + 'third-party//rust:serde_json', + 'third-party//rust:smallvec', + 'third-party//rust:strsim', + 'third-party//rust:tempfile', + 'third-party//rust:thiserror', + 'third-party//rust:tokio', + 'third-party//rust:tracing', + 'third-party//rust:watchman_client', + 'third-party//rust:whoami', + 'third-party//rust:zstd', + # CARGO-SYNC-END +]) + select({ + "config//os:windows": [ + # CARGO-SYNC-START: dependencies@cfg(windows) + 'third-party//rust:winreg', + # CARGO-SYNC-END + ], + "DEFAULT": [ + # CARGO-SYNC-START: dependencies@cfg(unix) + 'third-party//rust:rustix', + # CARGO-SYNC-END + ], +}) + +jj.rust_library( + name = "jj-lib-full", + crate = "jj_lib", + srcs = glob([ + "src/**/*.pest", + "src/**/*.rs", + ], exclude = [ + "src/protos/*.rs" + ]), + mapped_srcs = { + "//lib/gen-protos:protos.rs": "src/protos", + }, + features = [ + "watchman", + "git", + ], + deps = COMMON_DEPS + FULL_DEPS, +) + +jj.rust_library( + name = "jj-lib-core", + crate = "jj_lib", + srcs = glob([ + "src/**/*.pest", + "src/**/*.rs", + ], exclude = [ + "src/protos/*.rs" + ]), + mapped_srcs = { + "//lib/gen-protos:protos.rs": "src/protos", + }, + + deps = COMMON_DEPS, +) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index e6a47dede4..16eba83a8c 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -21,6 +21,8 @@ include = [ "!*.snap*", ] +[lints] +workspace = true [[test]] name = "runner" diff --git a/lib/PACKAGE b/lib/PACKAGE new file mode 100644 index 0000000000..9bf0691b15 --- /dev/null +++ b/lib/PACKAGE @@ -0,0 +1,5 @@ + +package( + inherit = True, + visibility = [ 'PUBLIC' ], +) diff --git a/lib/src/fileset_parser.rs b/lib/src/fileset_parser.rs index 7b0a30aada..39e9c09cc2 100644 --- a/lib/src/fileset_parser.rs +++ b/lib/src/fileset_parser.rs @@ -26,6 +26,12 @@ use thiserror::Error; use crate::dsl_util::{self, InvalidArguments, StringLiteralParser}; +#[cfg(buck_build)] +#[derive(Parser)] +#[grammar = "lib/src/fileset.pest"] +struct FilesetParser; + +#[cfg(not(buck_build))] #[derive(Parser)] #[grammar = "fileset.pest"] struct FilesetParser; diff --git a/lib/src/revset_parser.rs b/lib/src/revset_parser.rs index e7fef5f7e4..d35c72d5b3 100644 --- a/lib/src/revset_parser.rs +++ b/lib/src/revset_parser.rs @@ -32,6 +32,12 @@ use crate::dsl_util::{ FoldableExpression, InvalidArguments, KeywordArgument, StringLiteralParser, }; +#[cfg(buck_build)] +#[derive(Parser)] +#[grammar = "lib/src/revset.pest"] +struct RevsetParser; + +#[cfg(not(buck_build))] #[derive(Parser)] #[grammar = "revset.pest"] struct RevsetParser;