From d24cbf75269a43d8ec7cb1ba6709c592b4706303 Mon Sep 17 00:00:00 2001 From: Josef Svenningsson Date: Mon, 4 Nov 2024 04:19:19 -0800 Subject: [PATCH] Annotate generated thrift structs with rust.Ord Summary: We're now generating `set<>` types in thrift. In rust, these are translated to sets which use ordering, so all predicates need to implement the `Ord` trait. Reviewed By: donsbot Differential Revision: D65270915 fbshipit-source-id: 6fda2c97a00ba7d0a6d803cca83f84a3a3a79f45 --- Makefile | 1 + glean.cabal.in | 1 + glean/schema/gen/Glean/Schema/Gen/Thrift.hs | 12 +++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 7860b2008..48cb07502 100644 --- a/Makefile +++ b/Makefile @@ -260,6 +260,7 @@ THRIFT_GLEAN= \ glean/config/client/client_config.thrift \ thrift/annotation/cpp.thrift \ thrift/annotation/hack.thrift \ + thrift/annotation/rust.thrift \ thrift/annotation/scope.thrift \ thrift/annotation/thrift.thrift diff --git a/glean.cabal.in b/glean.cabal.in index e875159d4..70d03c8ae 100644 --- a/glean.cabal.in +++ b/glean.cabal.in @@ -253,6 +253,7 @@ library thrift-annotation exposed-modules: Cpp.Types Hack.Types + Rust.Types Scope.Types Thrift.Types diff --git a/glean/schema/gen/Glean/Schema/Gen/Thrift.hs b/glean/schema/gen/Glean/Schema/Gen/Thrift.hs index 153b82a04..2643e3f31 100644 --- a/glean/schema/gen/Glean/Schema/Gen/Thrift.hs +++ b/glean/schema/gen/Glean/Schema/Gen/Thrift.hs @@ -97,6 +97,7 @@ genTargets slashVn info = , " thrift_srcs = { \"" <> namespace <> ".thrift\" : [] }," , " deps = [" <> Text.intercalate "," ( "\"//glean/if:glean\"" : depTargets ) <> + ", \"//thrift/annotation:rust\"" <> ", \"//thrift/annotation:thrift\"]," , " hs2_deps = [" , " \"//glean/hs:angle\"," @@ -225,7 +226,8 @@ genNamespace slashVn namespaces version , "// \x40generated" , "// @" <> "nolint" , "" - , "include \"glean/if/glean.thrift\"" ] ++ + , "include \"glean/if/glean.thrift\"" + , "include \"thrift/annotation/rust.thrift\""] ++ [ "include \"" <> thriftDir slashVn <> "/" <> underscored dep <> ".thrift\"" | dep <- deps ] ++ @@ -425,6 +427,7 @@ genPred here PredicateDef{..} = do , "version=" <> showt (predicateRef_version predicateDefRef) <> ";" ] , "}" + , "@rust.Ord" ] -- Predicate types can be recursive so those need to be refs in C++. @@ -504,10 +507,13 @@ genType here TypeDef{..} = addExtraDecls $ do tyName <- withFieldHint nm (thriftTy here ty) return $ makeField structOrUnion ix nm tyName let - define | null fields = allowReservedIdentifierAnnotation name + define | null fields = + "@rust.Ord\n" <> + allowReservedIdentifierAnnotation name <> "struct " <> name <> " {}" | otherwise = myUnlines $ concat - [ [ allowReservedIdentifierAnnotation name + [ [ "@rust.Ord\n" + <> allowReservedIdentifierAnnotation name <> structOrUnion <> " " <> name <> " {" ] , indentLines (fieldTexts ++ extraFields) , [ "}" ]