diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..a71aa90e --- /dev/null +++ b/.bazelrc @@ -0,0 +1 @@ +try-import user.bazelrc diff --git a/.gitignore b/.gitignore index e53acfd4..461de1ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +bazel-* +.bazel +user.bazelrc +.cpcache + /_build /bin /graphql_ppx*.exe diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000..7e3abb75 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,20 @@ +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") + +package(default_visibility = ["//visibility:public"]) + +exports_files(["graphql_schema.json"]) + +bool_flag( name = "always-link", build_setting_default = False ) +config_setting(name = "enable_always_link", flag_values = {":always-link": str(True)}) + +bool_flag( name = "debug", build_setting_default = True ) +config_setting(name = "enable_debug", flag_values = {":debug": str(True)}) + +bool_flag( name = "threads", build_setting_default = True ) +config_setting(name = "enable_threads", flag_values = {":threads": str(True)}) + +bool_flag( name = "tooling", build_setting_default = False ) +config_setting(name = "enable_tooling", flag_values = {":tooling": str(True)}) + +bool_flag( name = "verbose", build_setting_default = False ) +config_setting(name = "enable_verbose", flag_values = {":verbose": str(True)}) diff --git a/BUILD.bzl b/BUILD.bzl new file mode 100644 index 00000000..8d6ef07f --- /dev/null +++ b/BUILD.bzl @@ -0,0 +1,38 @@ +REPO_ALWAYS_LINK = select({ + "//:enable_always_link": ["-linkall"], + "//conditions:default": [], +}) + +REPO_DEBUG = select({ + "//:enable_debug": ["-g"], + "//conditions:default": [], +}) + +REPO_THREADS = select({ + "//:enable_threads": ["-thread"], + "//conditions:default": [], +}) + +REPO_VERBOSE = select({ + "//:enable_verbose": ["-verbose"], + "//conditions:default": [], +}) + +## FIXME: settle on defaults +# DEFAULT_WARNINGS = ["-w", "+a-4-6-7-9-27-29-32..42-44-45-48-50-60"] +# WARNINGS = ["-w", "@a-4-29-40-41-42-44-45-48-58-59-60"] +# MODULE_WARNINGS = ["-w", "@1..3@5..28@30..39@43@46..47@49..57@61..62-40"] + +REPO_DEFAULT_OPTS = ["-strict-formats", "-short-paths", "-keep-locs"] + +REPO_OPTS = REPO_DEFAULT_OPTS + REPO_THREADS + REPO_ALWAYS_LINK + REPO_VERBOSE + REPO_DEBUG +REPO_ARCHIVE_OPTS = REPO_OPTS +REPO_EXECUTABLE_OPTS = REPO_OPTS +REPO_INTERFACE_OPTS = REPO_OPTS +REPO_MODULE_OPTS = REPO_OPTS +REPO_NS_MODULE_OPTS = REPO_OPTS + +REPO_PPX_ARCHIVE_OPTS = REPO_OPTS +REPO_PPX_EXECUTABLE_OPTS = REPO_OPTS + ["-linkall", "-predicates", "ppx_driver"] +REPO_PPX_INTERFACE_OPTS = REPO_OPTS +REPO_PPX_MODULE_OPTS = REPO_OPTS diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel new file mode 100644 index 00000000..f8806436 --- /dev/null +++ b/WORKSPACE.bazel @@ -0,0 +1,25 @@ +workspace( name = "graphql_ppx" ) + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +############# +http_archive( + name = "bazel_skylib", + urls = [ + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz", + ], + sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c", +) +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") +bazel_skylib_workspace() + +############### +git_repository( + name = "obazl_rules_ocaml", + remote = "https://github.com/obazl/rules_ocaml", + branch = "master", +) +load("@obazl_rules_ocaml//ocaml:bootstrap.bzl", "ocaml_configure") +ocaml_configure() diff --git a/bzl/host/BUILD.bazel b/bzl/host/BUILD.bazel new file mode 100644 index 00000000..d147227c --- /dev/null +++ b/bzl/host/BUILD.bazel @@ -0,0 +1,35 @@ +package(default_visibility = ["//visibility:public"]) + +config_setting( + name = "linux", + constraint_values = [ + "@platforms//os:linux", + ] +) + +config_setting( + name = "linux_x64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ] +) + +config_setting( + name = "macos", + constraint_values = ["@platforms//os:macos"] +) + +config_setting( + name = "m32", + constraint_values = [ + "@platforms//cpu:x86_32", + ] +) + +config_setting( + name = "m64", + constraint_values = [ + "@platforms//cpu:x86_64", + ] +) diff --git a/bzl/obazl.edn b/bzl/obazl.edn new file mode 100644 index 00000000..cdf74a43 --- /dev/null +++ b/bzl/obazl.edn @@ -0,0 +1,36 @@ +;; Obazl tool configuration map +;; FIXME: one config map per workspace +{ + + ;; TODO + :overrides { + ;; symbol label + Digestif "@opam//pkg:digestif.c" + } + :workspace "mina" + :cc-stuff { + } + :injected-deps { + ;; these are deps that are injected by ppx, and cannot be handled by the converter + } + :exclusions #{ + ;; list of dune files to NOT convert automatically + "dune" + } + :ns-sep "__" + :opam { + :pins { + ;; will be omitted from @u/local-deps cached list, so deps will be @opam//pkg + } + } + :ppx {:shared-pkg "//bzl/ppx" + :runtime-data { + "../graphql_schema.json" {:var GRAPHQL_SCHEMA_TARGET :target "//:graphql_schema.json"} + } + } + :profiles { + :all {:flags [:standard "-short-paths" "-cclib" "-ljemalloc" + "-w" "e@a-4-29-40-41-42-44-45-48-58-59-60"] + :src "src/dune.flags.inc"} + } + } diff --git a/bzl/ppx/BUILD.bazel b/bzl/ppx/BUILD.bazel new file mode 100644 index 00000000..82f82c97 --- /dev/null +++ b/bzl/ppx/BUILD.bazel @@ -0,0 +1,112 @@ +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") +load("@obazl_rules_ocaml//ocaml:rules.bzl", "ppx_executable", "ppx_module") +load("//:BUILD.bzl", "REPO_PPX_EXECUTABLE_OPTS") +load(":BUILD.bzl", "PKG_PPX_EXECUTABLE_OPTS") + +THIS_PPX_EXECUTABLE_OPTS = REPO_PPX_EXECUTABLE_OPTS + PKG_PPX_EXECUTABLE_OPTS + +############### +ppx_executable( + name = "ppx.exe[ppx_tools_versioned.metaquot_402]", + main = ":Driver", + opts = THIS_PPX_EXECUTABLE_OPTS, + visibility = [ + "//src/base:__pkg__", + "//src/bucklescript:__pkg__", + ], + deps = [ + "@opam//pkg:ppx_tools_versioned.metaquot_402", + "@opam//pkg:ppxlib", + ], +) + +########### +ppx_module( + name = "Driver", + src = ":ppxlib_driver.ml", + opts = ["-linkall"], + visibility = ["//visibility:public"], + deps = ["@opam//pkg:ppxlib"], +) + +######## +genrule( + name = "gendriver", + outs = ["ppxlib_driver.ml"], + cmd = "\n".join([ + "echo \"(* GENERATED FILE - DO NOT EDIT *)\" > \"$@\"", + "echo \"let () = Ppxlib.Driver.standalone ()\" >> \"$@\"", + ]), +) + +################################################################### +######## Configuration Settings - see :BUILD.bzl ################# +bool_flag( + name = "always-link", + build_setting_default = False, +) + +config_setting( + name = "enable_always_link", + flag_values = {":always-link": str(True)}, +) + +bool_flag( + name = "debug", + build_setting_default = True, +) + +config_setting( + name = "enable_debug", + flag_values = {":debug": str(True)}, +) + +bool_flag( + name = "threads", + build_setting_default = True, +) + +config_setting( + name = "enable_threads", + flag_values = {":threads": str(True)}, +) + +bool_flag( + name = "tooling", + build_setting_default = False, +) + +config_setting( + name = "enable_tooling", + flag_values = {":tooling": str(True)}, +) + +bool_flag( + name = "verbose", + build_setting_default = False, +) + +config_setting( + name = "enable_verbose", + flag_values = {":verbose": str(True)}, +) + +## PPX control +string_flag( + name = "ppx-out", + build_setting_default = "binary", + values = [ + "binary", + "text", + ], +) + +config_setting( + name = "enable_ppx_output_format_text", + flag_values = {":ppx-out": "text"}, +) + +config_setting( + name = "enable_ppx_output_format_binary", + flag_values = {":ppx-out": "binary"}, +) diff --git a/bzl/ppx/BUILD.bzl b/bzl/ppx/BUILD.bzl new file mode 100644 index 00000000..8cced7a6 --- /dev/null +++ b/bzl/ppx/BUILD.bzl @@ -0,0 +1,8 @@ +## ppx_pkg_bzl.mustache +PKG_ALWAYS_LINK_OPT = select({":enable_always_link": ["-linkall"], "//conditions:default": []}) +PKG_DEBUG_OPT = select({":enable_debug": ["-g"], "//conditions:default": []}) +PKG_THREADS_OPT = select({":enable_threads": ["-thread"], "//conditions:default": []}) +PKG_TOOLING_OPT = select({":enable_tooling": ["-bin-annot"], "//conditions:default": []}) +PKG_VERBOSE_OPT = select({":enable_verbose": ["-verbose"], "//conditions:default": []}) + +PKG_PPX_EXECUTABLE_OPTS = PKG_ALWAYS_LINK_OPT + PKG_DEBUG_OPT + PKG_THREADS_OPT + PKG_TOOLING_OPT + PKG_VERBOSE_OPT diff --git a/bzl/tools/aliases b/bzl/tools/aliases new file mode 100644 index 00000000..73c011cc --- /dev/null +++ b/bzl/tools/aliases @@ -0,0 +1,2 @@ +# source me +alias "bl=less `bazel info command_log`" \ No newline at end of file diff --git a/bzl/tools/user.bazelrc.tpl b/bzl/tools/user.bazelrc.tpl new file mode 100644 index 00000000..7ab97a95 --- /dev/null +++ b/bzl/tools/user.bazelrc.tpl @@ -0,0 +1,22 @@ +# do not use on MacOS: +# build --symlink_prefix=.bazel/ # use hidden dirs instead of top-level symlinks +# do not create `bazel-out` symlink if a different name is given to `--symlink_prefix`. +# build --experimental_no_product_name_out_symlink + +build --color=yes +build --subcommands=pretty_print +build --verbose_failures +build --sandbox_debug + +# build --show_timestamps +# build --keep_going +# build --jobs 600 +# query --keep_going + +## when running tests this will provide hints for 'size' or 'timeout' attribs: +# test --test_verbose_timeout_warnings + +## Override the WORKSPACE definition of a repo: + +# 'common' - applies to both build and query commands +# common --override_repository=obazl_rules_ocaml=/path/to/obazl diff --git a/bzl/tools/wss b/bzl/tools/wss new file mode 100755 index 00000000..897da306 --- /dev/null +++ b/bzl/tools/wss @@ -0,0 +1,23 @@ +#!/bin/sh + +for LAST; do true; done + +ARGS= +for param in "$@" +do + echo COUNT: $# + if [ $# -ne 1 ] + then + ARGS="$ARGS $1" + fi + shift +done + +# if no dir arg is passed: +if [[ $LAST == -* ]] +then + ARGS="$ARGS $LAST" + LAST= +fi + +ls --color $ARGS `bazel info output_base`/external/$LAST diff --git a/discover/README.bazel.md b/discover/README.bazel.md new file mode 100644 index 00000000..8e12d1f4 --- /dev/null +++ b/discover/README.bazel.md @@ -0,0 +1,2 @@ +This package is not needed by the Bazel build, which can construct +flags without building and running an OCaml executable. diff --git a/src/BUILD.bazel b/src/BUILD.bazel new file mode 100644 index 00000000..496b70f0 --- /dev/null +++ b/src/BUILD.bazel @@ -0,0 +1,32 @@ +## OBAZL GENERATED FILE ## To retain edits (prevent overwrite), delete this line. + +load("@obazl_rules_ocaml//ocaml:rules.bzl", +) +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") +load("//:BUILD.bzl", +) +load(":BUILD.bzl", +) + + +################################################################### +######## Configuration Settings - see :BUILD.bzl ################# +bool_flag( name = "always-link", build_setting_default = False ) +config_setting(name = "enable_always_link", flag_values = {":always-link": str(True)}) + +bool_flag( name = "debug", build_setting_default = True ) +config_setting(name = "enable_debug", flag_values = {":debug": str(True)}) + +bool_flag( name = "threads", build_setting_default = True ) +config_setting(name = "enable_threads", flag_values = {":threads": str(True)}) + +bool_flag( name = "tooling", build_setting_default = False ) +config_setting(name = "enable_tooling", flag_values = {":tooling": str(True)}) + +bool_flag( name = "verbose", build_setting_default = False ) +config_setting(name = "enable_verbose", flag_values = {":verbose": str(True)}) + +## PPX control +string_flag( name = "ppx-out", build_setting_default = "binary", values = ["binary", "text"]) +config_setting( name = "enable_ppx_output_format_text", flag_values = { ":ppx-out": "text" }) +config_setting( name = "enable_ppx_output_format_binary", flag_values = { ":ppx-out": "binary" }) diff --git a/src/BUILD.bzl b/src/BUILD.bzl new file mode 100644 index 00000000..e375bdb3 --- /dev/null +++ b/src/BUILD.bzl @@ -0,0 +1,9 @@ +"""Package variables module. + +Package-scoped configuration variable definitions. +""" + +PKG_DEBUG_OPT = select({":enable_debug": ["-g"], "//conditions:default": []}) +PKG_VERBOSE_OPT = select({":enable_verbose": ["-verbose"], "//conditions:default": []}) + +PKG_OPTS = PKG_DEBUG_OPT + PKG_VERBOSE_OPT diff --git a/src/base/BUILD.bazel b/src/base/BUILD.bazel new file mode 100644 index 00000000..4ae467a6 --- /dev/null +++ b/src/base/BUILD.bazel @@ -0,0 +1,645 @@ +## OBAZL GENERATED FILE ## To retain edits (prevent overwrite), delete this line. + +load( + "@obazl_rules_ocaml//ocaml:rules.bzl", + "ocaml_archive", + "ocaml_module", + "ocaml_ns", + "xrule_cppo_filegroup", +) +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") +load( + "//:BUILD.bzl", + "REPO_ARCHIVE_OPTS", + "REPO_MODULE_OPTS", + "REPO_NS_MODULE_OPTS", +) +load( + ":BUILD.bzl", + "PKG_ARCHIVE_OPTS", + "PKG_MODULE_OPTS", + "PKG_NS_MODULE_OPTS", +) + +################################################################ +## STANZA 1: LIBRARY GRAPHQL_PPX_BASE +################################################################ +GRAPHQL_PPX_BASE_MODULE_OPTS = REPO_MODULE_OPTS + PKG_MODULE_OPTS + +GRAPHQL_PPX_BASE_NS_MODULE_OPTS = REPO_NS_MODULE_OPTS + PKG_NS_MODULE_OPTS + +GRAPHQL_PPX_BASE_ARCHIVE_OPTS = REPO_ARCHIVE_OPTS + PKG_ARCHIVE_OPTS + [] + +GRAPHQL_PPX_BASE_NS_MODULE_OPTS = REPO_NS_MODULE_OPTS + PKG_NS_MODULE_OPTS + +GRAPHQL_PPX_BASE_NS_MODULE_OPTS = REPO_NS_MODULE_OPTS + PKG_NS_MODULE_OPTS + +GRAPHQL_PPX_BASE_DEPS = [ + # do not sort (buildifier) + "@opam//pkg:unix", + "@opam//pkg:result", + "@opam//pkg:yojson", +] + +GRAPHQL_PPX_BASE_PPX = "@//bzl/ppx:ppx.exe[ppx_tools_versioned.metaquot_402]" + +GRAPHQL_PPX_BASE_PPX_ARGS = [ + # do not sort (buildifier) +] + +############## +ocaml_archive( + name = "graphql_ppx_base", + opts = GRAPHQL_PPX_BASE_ARCHIVE_OPTS, + visibility = ["//visibility:public"], + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Ast_serializer_apollo", + ":_Build_config", + ":_Compat", + ":_Dirty_checker", + ":_Generator_utils", + ":_Graphql_ast", + ":_Graphql_lexer", + ":_Graphql_parser", + ":_Graphql_parser_document", + ":_Graphql_parser_value", + ":_Graphql_ppx_base", + ":_Graphql_printer", + ":_Log", + ":_Multi_visitor", + ":_Option", + ":_Ppx_config", + ":_Read_schema", + ":_Result_decoder", + ":_Result_ext", + ":_Result_structure", + ":_Rule_known_argument_names", + ":_Rule_no_unused_variables", + ":_Schema", + ":_Source_pos", + ":_Traversal_utils", + ":_Type_utils", + ":_Validations", + ], +) + +######### +ocaml_ns( + name = "Graphql_ppx_base_ns", + ns = "graphql_ppx_base", + opts = GRAPHQL_PPX_BASE_NS_MODULE_OPTS, + submodules = [ + # do not sort (buildifier) + "ast_serializer_apollo.ml", + "compat.ml", + "dirty_checker.ml", + "generator_utils.ml", + "graphql_ast.ml", + "graphql_lexer.ml", + "graphql_parser.ml", + "graphql_parser_document.ml", + "graphql_parser_value.ml", + "graphql_ppx_base.ml", + "graphql_printer.ml", + "log.ml", + "multi_visitor.ml", + "option.ml", + "ppx_config.ml", + "read_schema.ml", + "result_decoder.ml", + "result_ext.ml", + "result_structure.ml", + "rule_known_argument_names.ml", + "rule_no_unused_variables.ml", + "schema.ml", + "source_pos.ml", + "traversal_utils.ml", + "type_utils.ml", + "validations.ml", + "build_config.ml" + ], +) + +############# +ocaml_module( + name = "_Ast_serializer_apollo", + src = "ast_serializer_apollo.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Graphql_ast", + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Compat", + src = "compat.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [":_Build_config"] +) + +############# +ocaml_module( + name = "_Dirty_checker", + src = "dirty_checker.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Log", + ], +) + +############# +ocaml_module( + name = "_Generator_utils", + src = "generator_utils.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Compat", + ":_Graphql_ast", + ":_Ppx_config", + ":_Schema", + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Graphql_ast", + src = "graphql_ast.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Graphql_lexer", + src = "graphql_lexer.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Graphql_parser", + src = "graphql_parser.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Graphql_lexer", + ":_Result_ext", + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Graphql_parser_document", + src = "graphql_parser_document.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Graphql_ast", + ":_Graphql_lexer", + ":_Graphql_parser", + ":_Graphql_parser_value", + ":_Result_ext", + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Graphql_parser_value", + src = "graphql_parser_value.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Graphql_ast", + ":_Graphql_lexer", + ":_Graphql_parser", + ":_Result_ext", + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Graphql_ppx_base", + src = "graphql_ppx_base.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Ast_serializer_apollo", + ":_Compat", + ":_Generator_utils", + ":_Graphql_ast", + ":_Graphql_lexer", + ":_Graphql_parser", + ":_Graphql_parser_document", + ":_Graphql_printer", + ":_Log", + ":_Option", + ":_Ppx_config", + ":_Read_schema", + ":_Result_decoder", + ":_Result_structure", + ":_Schema", + ":_Source_pos", + ":_Traversal_utils", + ":_Type_utils", + ":_Validations", + ], +) + +############# +ocaml_module( + name = "_Graphql_printer", + src = "graphql_printer.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Graphql_ast", + ":_Option", + ":_Ppx_config", + ":_Schema", + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Log", + src = "log.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Ppx_config", + ], +) + +############# +ocaml_module( + name = "_Multi_visitor", + src = "multi_visitor.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Traversal_utils", + ], +) + +############# +ocaml_module( + name = "_Option", + src = "option.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS, +) + +############# +ocaml_module( + name = "_Ppx_config", + src = "ppx_config.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Option", + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Read_schema", + src = "read_schema.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS + ["-linkall"], + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Dirty_checker", + ":_Log", + ":_Ppx_config", + ":_Schema", + ], +) + +############# +ocaml_module( + name = "_Result_decoder", + src = "result_decoder.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Generator_utils", + ":_Graphql_ast", + ":_Option", + ":_Result_structure", + ":_Schema", + ":_Source_pos", + ":_Type_utils", + ], +) + +############# +ocaml_module( + name = "_Result_ext", + src = "result_ext.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS, +) + +############# +ocaml_module( + name = "_Result_structure", + src = "result_structure.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Graphql_ast", + ":_Schema", + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Rule_known_argument_names", + src = "rule_known_argument_names.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Graphql_ast", + ":_Option", + ":_Schema", + ":_Source_pos", + ":_Traversal_utils", + ], +) + +############# +ocaml_module( + name = "_Rule_no_unused_variables", + src = "rule_no_unused_variables.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Graphql_ast", + ":_Source_pos", + ":_Traversal_utils", + ], +) + +############# +ocaml_module( + name = "_Schema", + src = "schema.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS, +) + +############# +ocaml_module( + name = "_Source_pos", + src = "source_pos.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS, +) + +############# +ocaml_module( + name = "_Traversal_utils", + src = "traversal_utils.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Generator_utils", + ":_Graphql_ast", + ":_Option", + ":_Result_structure", + ":_Schema", + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Type_utils", + src = "type_utils.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Graphql_ast", + ":_Schema", + ":_Source_pos", + ], +) + +############# +ocaml_module( + name = "_Validations", + src = "validations.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + ":_Multi_visitor", + ":_Rule_known_argument_names", + ":_Rule_no_unused_variables", + ":_Traversal_utils", + ], +) + +############# +ocaml_module( + name = "_Build_config", + src = ":gensrcs", + # src = "build_config.ml", + ns = ":Graphql_ppx_base_ns", + opts = GRAPHQL_PPX_BASE_MODULE_OPTS, + ppx = GRAPHQL_PPX_BASE_PPX, + ppx_args = GRAPHQL_PPX_BASE_PPX_ARGS, + deps = GRAPHQL_PPX_BASE_DEPS + [ + # do not sort (buildifier) + # ":_Multi_visitor", + # ":_Rule_known_argument_names", + # ":_Rule_no_unused_variables", + # ":_Traversal_utils", + ], +) + +genrule( + name = "gensrcs", + srcs = ["build_config.cppo.ml"], + outs = ["build_config.ml"], + tools = ["@ocaml//tools:cppo"], + cmd = " ".join([ + "$(location @ocaml//tools:cppo) -V OCAML:4.07.1 -o $@ $<" + ]), +) + +##################### +# xrule_cppo_filegroup( +# name = "cppo", +# srcs = ["build_config.cppo.ml"], +# outs = ["build_config.ml"], +# vars = { "@ocaml//version": "OCAML"} ## "%{ocaml_version}" } +# ) + +################################################################### +######## Configuration Settings - see :BUILD.bzl ################# +bool_flag( + name = "always-link", + build_setting_default = False, +) + +config_setting( + name = "enable_always_link", + flag_values = {":always-link": str(True)}, +) + +bool_flag( + name = "debug", + build_setting_default = True, +) + +config_setting( + name = "enable_debug", + flag_values = {":debug": str(True)}, +) + +bool_flag( + name = "threads", + build_setting_default = True, +) + +config_setting( + name = "enable_threads", + flag_values = {":threads": str(True)}, +) + +bool_flag( + name = "tooling", + build_setting_default = False, +) + +config_setting( + name = "enable_tooling", + flag_values = {":tooling": str(True)}, +) + +bool_flag( + name = "verbose", + build_setting_default = False, +) + +config_setting( + name = "enable_verbose", + flag_values = {":verbose": str(True)}, +) + +## PPX control +string_flag( + name = "ppx-out", + build_setting_default = "binary", + values = [ + "binary", + "text", + ], +) + +config_setting( + name = "enable_ppx_output_format_text", + flag_values = {":ppx-out": "text"}, +) + +config_setting( + name = "enable_ppx_output_format_binary", + flag_values = {":ppx-out": "binary"}, +) diff --git a/src/base/BUILD.bzl b/src/base/BUILD.bzl new file mode 100644 index 00000000..5248f625 --- /dev/null +++ b/src/base/BUILD.bzl @@ -0,0 +1,15 @@ +"""Package variables module. + +Package-scoped configuration variable definitions. +""" + +PKG_DEBUG_OPT = select({":enable_debug": ["-g"], "//conditions:default": []}) +PKG_VERBOSE_OPT = select({":enable_verbose": ["-verbose"], "//conditions:default": []}) + +PKG_OPTS = PKG_DEBUG_OPT + PKG_VERBOSE_OPT + +PKG_MODULE_OPTS = PKG_OPTS + +PKG_ARCHIVE_OPTS = PKG_OPTS + +PKG_NS_MODULE_OPTS = PKG_OPTS diff --git a/src/bucklescript/BUILD.bazel b/src/bucklescript/BUILD.bazel new file mode 100644 index 00000000..e34f7289 --- /dev/null +++ b/src/bucklescript/BUILD.bazel @@ -0,0 +1,207 @@ +## NOTE: no dependency on `dune.flags` (produced by +## discover/discover.exe). Currently the discover exe produces no +## flags. If flags are neeeded they can be handled using Bazel +## mechanisms; the Bazel build does not need discover.exe. + +load( + "@obazl_rules_ocaml//ocaml:rules.bzl", + "ocaml_executable", + "ocaml_module", +) +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") +load( + "//:BUILD.bzl", + "REPO_EXECUTABLE_OPTS", + "REPO_MODULE_OPTS", +) +load( + ":BUILD.bzl", + "PKG_EXECUTABLE_OPTS", + "PKG_MODULE_OPTS", +) + +################################################################ +## STANZA 1: EXECUTABLE GRAPHQL_PPX +################################################################ +GRAPHQL_PPX_EXECUTABLE_OPTS = REPO_EXECUTABLE_OPTS + PKG_EXECUTABLE_OPTS + +GRAPHQL_PPX_MODULE_OPTS = REPO_MODULE_OPTS + PKG_MODULE_OPTS + +GRAPHQL_PPX_DEPS = [ + # do not sort (buildifier) + "@opam//pkg:ocaml-migrate-parsetree", + "@graphql_ppx//src/base:graphql_ppx_base", +] + +GRAPHQL_PPX_PPX = "@//bzl/ppx:ppx.exe[ppx_tools_versioned.metaquot_402]" + +GRAPHQL_PPX_PPX_ARGS = [ + # do not sort (buildifier) +] + +################# +ocaml_executable( + name = "graphql_ppx.exe", + main = ":_Graphql_ppx", + opts = GRAPHQL_PPX_EXECUTABLE_OPTS, + visibility = ["//visibility:public"], + deps = GRAPHQL_PPX_DEPS + [ + # do not sort (buildifier) + ":_Output_bucklescript_decoder", + ":_Output_bucklescript_encoder", + ":_Output_bucklescript_module", + ":_Output_bucklescript_unifier", + ":_Output_bucklescript_utils", + ], +) + +############# +ocaml_module( + name = "_Graphql_ppx", + src = "graphql_ppx.ml", + opts = GRAPHQL_PPX_MODULE_OPTS, + ppx = GRAPHQL_PPX_PPX, + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = GRAPHQL_PPX_DEPS + [ + # do not sort (buildifier) + ":_Output_bucklescript_module", + ":_Output_bucklescript_utils", + ], +) + +############# +ocaml_module( + name = "_Output_bucklescript_decoder", + src = "output_bucklescript_decoder.ml", + opts = GRAPHQL_PPX_MODULE_OPTS, + ppx = GRAPHQL_PPX_PPX, + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = GRAPHQL_PPX_DEPS + [ + # do not sort (buildifier) + ":_Output_bucklescript_utils", + ], +) + +############# +ocaml_module( + name = "_Output_bucklescript_encoder", + src = "output_bucklescript_encoder.ml", + opts = GRAPHQL_PPX_MODULE_OPTS, + ppx = GRAPHQL_PPX_PPX, + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = GRAPHQL_PPX_DEPS + [ + # do not sort (buildifier) + ":_Output_bucklescript_utils", + ], +) + +############# +ocaml_module( + name = "_Output_bucklescript_module", + src = "output_bucklescript_module.ml", + opts = GRAPHQL_PPX_MODULE_OPTS, + ppx = GRAPHQL_PPX_PPX, + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = GRAPHQL_PPX_DEPS + [ + # do not sort (buildifier) + ":_Output_bucklescript_decoder", + ":_Output_bucklescript_encoder", + ":_Output_bucklescript_unifier", + ], +) + +############# +ocaml_module( + name = "_Output_bucklescript_unifier", + src = "output_bucklescript_unifier.ml", + opts = GRAPHQL_PPX_MODULE_OPTS, + ppx = GRAPHQL_PPX_PPX, + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = GRAPHQL_PPX_DEPS + [ + # do not sort (buildifier) + ":_Output_bucklescript_encoder", + ":_Output_bucklescript_utils", + ], +) + +############# +ocaml_module( + name = "_Output_bucklescript_utils", + src = "output_bucklescript_utils.ml", + opts = GRAPHQL_PPX_MODULE_OPTS, + ppx = GRAPHQL_PPX_PPX, + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = GRAPHQL_PPX_DEPS, +) + +################################################################### +######## Configuration Settings - see :BUILD.bzl ################# +bool_flag( + name = "always-link", + build_setting_default = False, +) + +config_setting( + name = "enable_always_link", + flag_values = {":always-link": str(True)}, +) + +bool_flag( + name = "debug", + build_setting_default = True, +) + +config_setting( + name = "enable_debug", + flag_values = {":debug": str(True)}, +) + +bool_flag( + name = "threads", + build_setting_default = True, +) + +config_setting( + name = "enable_threads", + flag_values = {":threads": str(True)}, +) + +bool_flag( + name = "tooling", + build_setting_default = False, +) + +config_setting( + name = "enable_tooling", + flag_values = {":tooling": str(True)}, +) + +bool_flag( + name = "verbose", + build_setting_default = False, +) + +config_setting( + name = "enable_verbose", + flag_values = {":verbose": str(True)}, +) + +## PPX control +string_flag( + name = "ppx-out", + build_setting_default = "binary", + values = [ + "binary", + "text", + ], +) + +config_setting( + name = "enable_ppx_output_format_text", + flag_values = {":ppx-out": "text"}, +) + +config_setting( + name = "enable_ppx_output_format_binary", + flag_values = {":ppx-out": "binary"}, +) diff --git a/src/bucklescript/BUILD.bzl b/src/bucklescript/BUILD.bzl new file mode 100644 index 00000000..02a64b13 --- /dev/null +++ b/src/bucklescript/BUILD.bzl @@ -0,0 +1,13 @@ +"""Package variables module. + +Package-scoped configuration variable definitions. +""" + +PKG_DEBUG_OPT = select({":enable_debug": ["-g"], "//conditions:default": []}) +PKG_VERBOSE_OPT = select({":enable_verbose": ["-verbose"], "//conditions:default": []}) + +PKG_OPTS = PKG_DEBUG_OPT + PKG_VERBOSE_OPT + +PKG_EXECUTABLE_OPTS = PKG_OPTS + +PKG_MODULE_OPTS = PKG_OPTS diff --git a/src/native/BUILD.bazel b/src/native/BUILD.bazel new file mode 100644 index 00000000..ea898b85 --- /dev/null +++ b/src/native/BUILD.bazel @@ -0,0 +1,241 @@ +## OBAZL GENERATED FILE ## To retain edits (prevent overwrite), delete this line. + +load( + "@obazl_rules_ocaml//ocaml:rules.bzl", + "ocaml_ns", + "ppx_archive", + "ppx_executable", + "ppx_module", +) +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") +load( + "//:BUILD.bzl", + "REPO_NS_MODULE_OPTS", + "REPO_PPX_ARCHIVE_OPTS", + "REPO_PPX_EXECUTABLE_OPTS", + "REPO_PPX_MODULE_OPTS", +) +load( + ":BUILD.bzl", + "PKG_PPX_ARCHIVE_OPTS", + "PKG_PPX_EXECUTABLE_OPTS", + "PKG_PPX_MODULE_OPTS", +) + +THIS_PPX_EXECUTABLE_OPTS = REPO_PPX_EXECUTABLE_OPTS + PKG_PPX_EXECUTABLE_OPTS + +################################################################ +## STANZA 1: GRAPHQL_PPX +################################################################ +GRAPHQL_PPX_PPX_EXECUTABLE_OPTS = REPO_PPX_EXECUTABLE_OPTS + PKG_PPX_EXECUTABLE_OPTS + +GRAPHQL_PPX_PPX_MODULE_OPTS = REPO_PPX_MODULE_OPTS + PKG_PPX_MODULE_OPTS + +GRAPHQL_PPX_PPX_ARCHIVE_OPTS = REPO_PPX_ARCHIVE_OPTS + PKG_PPX_ARCHIVE_OPTS + [] + +GRAPHQL_PPX_DEPS = [ + # do not sort (buildifier) + "@opam//pkg:ppxlib", + "@graphql_ppx//src/base:graphql_ppx_base", +] + +GRAPHQL_PPX_PPX = "//bzl/ppx:ppx.exe[ppxlib.metaquot]" + +GRAPHQL_PPX_PPX_ARGS = [ + # do not sort (buildifier) +] + +############ +ppx_archive( + name = "graphql_ppx", + opts = GRAPHQL_PPX_PPX_ARCHIVE_OPTS, + visibility = ["//visibility:public"], + deps = GRAPHQL_PPX_DEPS + [ + # do not sort (buildifier) + ":Graphql_ppx", + ":Output_native_decoder", + ":Output_native_encoder", + ":Output_native_module", + ":Output_native_unifier", + ":Output_native_utils", + ], +) + +########### +ppx_module( + name = "Graphql_ppx", + src = "graphql_ppx.ml", + opts = GRAPHQL_PPX_PPX_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = [ + # do not sort (buildifier) + "@opam//pkg:ppxlib", + "@graphql_ppx//src/base:graphql_ppx_base", + "Output_native_module", + "Output_native_utils", + ], +) + +########### +ppx_module( + name = "Output_native_decoder", + src = "output_native_decoder.ml", + opts = GRAPHQL_PPX_PPX_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = [ + # do not sort (buildifier) + "@opam//pkg:ppxlib", + "@graphql_ppx//src/base:graphql_ppx_base", + "Output_native_utils", + ], +) + +########### +ppx_module( + name = "Output_native_encoder", + src = "output_native_encoder.ml", + opts = GRAPHQL_PPX_PPX_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = [ + # do not sort (buildifier) + "@opam//pkg:ppxlib", + "@graphql_ppx//src/base:graphql_ppx_base", + "Output_native_utils", + ], +) + +########### +ppx_module( + name = "Output_native_module", + src = "output_native_module.ml", + opts = GRAPHQL_PPX_PPX_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = [ + # do not sort (buildifier) + "@opam//pkg:ppxlib", + "@graphql_ppx//src/base:graphql_ppx_base", + "Output_native_decoder", + "Output_native_encoder", + "Output_native_unifier", + ], +) + +########### +ppx_module( + name = "Output_native_unifier", + src = "output_native_unifier.ml", + opts = GRAPHQL_PPX_PPX_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = [ + # do not sort (buildifier) + "@opam//pkg:ppxlib", + "@graphql_ppx//src/base:graphql_ppx_base", + "Output_native_encoder", + "Output_native_utils", + ], +) + +########### +ppx_module( + name = "Output_native_utils", + src = "output_native_utils.ml", + opts = GRAPHQL_PPX_PPX_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = GRAPHQL_PPX_PPX_ARGS, + deps = [ + # do not sort (buildifier) + "@opam//pkg:ppxlib", + "@graphql_ppx//src/base:graphql_ppx_base", + ], +) + +################################################################### +######## Configuration Settings - see :BUILD.bzl ################# +bool_flag( + name = "always-link", + build_setting_default = False, +) + +config_setting( + name = "enable_always_link", + flag_values = {":always-link": str(True)}, +) + +bool_flag( + name = "debug", + build_setting_default = True, +) + +config_setting( + name = "enable_debug", + flag_values = {":debug": str(True)}, +) + +bool_flag( + name = "threads", + build_setting_default = True, +) + +config_setting( + name = "enable_threads", + flag_values = {":threads": str(True)}, +) + +bool_flag( + name = "tooling", + build_setting_default = False, +) + +config_setting( + name = "enable_tooling", + flag_values = {":tooling": str(True)}, +) + +bool_flag( + name = "verbose", + build_setting_default = False, +) + +config_setting( + name = "enable_verbose", + flag_values = {":verbose": str(True)}, +) + +## PPX control +string_flag( + name = "ppx-out", + build_setting_default = "binary", + values = [ + "binary", + "text", + ], +) + +config_setting( + name = "enable_ppx_output_format_text", + flag_values = {":ppx-out": "text"}, +) + +config_setting( + name = "enable_ppx_output_format_binary", + flag_values = {":ppx-out": "binary"}, +) + +############### +ppx_executable( + name = "ppx1.exe", + main = "//bzl/ppx:Driver", + opts = THIS_PPX_EXECUTABLE_OPTS, + visibility = [ + "//src/native:__pkg__", + ], + deps = [ + "@opam//pkg:ppxlib", + "@opam//pkg:ppxlib.metaquot", + ], +) diff --git a/src/native/BUILD.bzl b/src/native/BUILD.bzl new file mode 100644 index 00000000..88954c5d --- /dev/null +++ b/src/native/BUILD.bzl @@ -0,0 +1,15 @@ +"""Package variables module. + +Package-scoped configuration variable definitions. +""" + +PKG_DEBUG_OPT = select({":enable_debug": ["-g"], "//conditions:default": []}) +PKG_VERBOSE_OPT = select({":enable_verbose": ["-verbose"], "//conditions:default": []}) + +PKG_OPTS = PKG_DEBUG_OPT + PKG_VERBOSE_OPT + +PKG_PPX_EXECUTABLE_OPTS = PKG_OPTS + +PKG_PPX_MODULE_OPTS = PKG_OPTS + +PKG_PPX_ARCHIVE_OPTS = PKG_OPTS diff --git a/tests_native/BUILD.bazel b/tests_native/BUILD.bazel new file mode 100644 index 00000000..fda510a6 --- /dev/null +++ b/tests_native/BUILD.bazel @@ -0,0 +1,523 @@ +## OBAZL GENERATED FILE ## To retain edits (prevent overwrite), delete this line. + +load( + "@obazl_rules_ocaml//ocaml:rules.bzl", + "ocaml_archive", + "ocaml_module", + "ppx_executable", +) +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") +load( + "//:BUILD.bzl", + "REPO_ARCHIVE_OPTS", + "REPO_MODULE_OPTS", + "REPO_PPX_EXECUTABLE_OPTS", +) +load( + ":BUILD.bzl", + "PKG_ARCHIVE_OPTS", + "PKG_MODULE_OPTS", + "PKG_PPX_EXECUTABLE_OPTS", +) + +GRAPHQL_SCHEMA_TARGET = "//:graphql_schema.json" +GRAPHQL_SCHEMA_FILE = "graphql_schema.json" + +################################################################ +## STANZA 1: LIBRARY GRAPHQL_PPX_TEST +################################################################ +GRAPHQL_PPX_TEST_ARCHIVE_OPTS = REPO_ARCHIVE_OPTS + PKG_ARCHIVE_OPTS + [] + +GRAPHQL_PPX_TEST_MODULE_OPTS = REPO_MODULE_OPTS + PKG_MODULE_OPTS + +GRAPHQL_PPX_TEST_PPX_EXECUTABLE_OPTS = REPO_PPX_EXECUTABLE_OPTS + PKG_PPX_EXECUTABLE_OPTS + +GRAPHQL_PPX_TEST_DEPS = [ + # do not sort (buildifier) + "@opam//pkg:alcotest", + "@opam//pkg:yojson", + "@opam//pkg:str", +] + +############# +ocaml_module( + name = "_Arg_named_query", + src = "arg_named_query.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Comment", + src = "comment.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS, +) + +############# +ocaml_module( + name = "_Custom_decoder", + src = "custom_decoder.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS, +) + +############# +ocaml_module( + name = "_Custom_scalars", + src = "custom_scalars.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Enum_input", + src = "enum_input.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Fragment_definition", + src = "fragment_definition.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Interface", + src = "interface.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS, +) + +############# +ocaml_module( + name = "_List_args", + src = "list_args.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_List_inputs", + src = "list_inputs.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Lists", + src = "lists.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Main", + src = "main.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Arg_named_query", + ":_Custom_decoder", + ":_Custom_scalars", + ":_Enum_input", + ":_Fragment_definition", + ":_Interface", + ":_List_args", + ":_List_inputs", + ":_Lists", + ":_Mutation", + ":_Nested", + ":_Nonrecursive_input", + ":_Record", + ":_Recursive_input", + ":_Scalars", + ":_Scalars_args", + ":_Scalars_input", + ":_Skip_directives", + ":_Typename", + ":_Union", + ":_Union_partial", + ":_Variant", + ], +) + +############# +ocaml_module( + name = "_Mutation", + src = "mutation.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS, +) + +############# +ocaml_module( + name = "_Nested", + src = "nested.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Nonrecursive_input", + src = "nonrecursive_input.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Record", + src = "record.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS, +) + +############# +ocaml_module( + name = "_Recursive_input", + src = "recursive_input.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Scalars", + src = "scalars.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Scalars_args", + src = "scalars_args.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Scalars_input", + src = "scalars_input.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Skip_directives", + src = "skip_directives.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Test_shared", + src = "test_shared.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS, +) + +############# +ocaml_module( + name = "_Typename", + src = "typename.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +############# +ocaml_module( + name = "_Union", + src = "union.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS, +) + +############# +ocaml_module( + name = "_Union_partial", + src = "union_partial.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS, +) + +############# +ocaml_module( + name = "_Variant", + src = "variant.ml", + opts = GRAPHQL_PPX_TEST_MODULE_OPTS, + ppx = ":ppx1.exe", + ppx_args = [ + "-schema={}".format(GRAPHQL_SCHEMA_FILE) + ], + ppx_data = [GRAPHQL_SCHEMA_TARGET], + deps = GRAPHQL_PPX_TEST_DEPS + [ + # do not sort (buildifier) + ":_Test_shared", + ], +) + +################################################################### +######## Configuration Settings - see :BUILD.bzl ################# +bool_flag( + name = "always-link", + build_setting_default = False, +) + +config_setting( + name = "enable_always_link", + flag_values = {":always-link": str(True)}, +) + +bool_flag( + name = "debug", + build_setting_default = True, +) + +config_setting( + name = "enable_debug", + flag_values = {":debug": str(True)}, +) + +bool_flag( + name = "threads", + build_setting_default = True, +) + +config_setting( + name = "enable_threads", + flag_values = {":threads": str(True)}, +) + +bool_flag( + name = "tooling", + build_setting_default = False, +) + +config_setting( + name = "enable_tooling", + flag_values = {":tooling": str(True)}, +) + +bool_flag( + name = "verbose", + build_setting_default = False, +) + +config_setting( + name = "enable_verbose", + flag_values = {":verbose": str(True)}, +) + +## PPX control +string_flag( + name = "ppx-out", + build_setting_default = "binary", + values = [ + "binary", + "text", + ], +) + +config_setting( + name = "enable_ppx_output_format_text", + flag_values = {":ppx-out": "text"}, +) + +config_setting( + name = "enable_ppx_output_format_binary", + flag_values = {":ppx-out": "binary"}, +) + +############### +ppx_executable( + name = "ppx1.exe", + main = "//bzl/ppx:Driver", + opts = GRAPHQL_PPX_TEST_PPX_EXECUTABLE_OPTS, + visibility = [ + "//tests_native:__pkg__", + ], + deps = [ + "@graphql_ppx//src/native:graphql_ppx", + "@opam//pkg:ppxlib", + ], +) diff --git a/tests_native/BUILD.bzl b/tests_native/BUILD.bzl new file mode 100644 index 00000000..577f8329 --- /dev/null +++ b/tests_native/BUILD.bzl @@ -0,0 +1,14 @@ +"""Package variables module. + +Package-scoped configuration variable definitions. +""" + +PKG_DEBUG_OPT = select({":enable_debug": ["-g"], "//conditions:default": []}) +PKG_VERBOSE_OPT = select({":enable_verbose": ["-verbose"], "//conditions:default": []}) + +PKG_OPTS = PKG_DEBUG_OPT + PKG_VERBOSE_OPT +PKG_ARCHIVE_OPTS = PKG_OPTS + +PKG_MODULE_OPTS = PKG_OPTS + +PKG_PPX_EXECUTABLE_OPTS = PKG_OPTS