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

Bazel: initial commit #2

Merged
merged 1 commit into from Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelrc
@@ -0,0 +1 @@
try-import user.bazelrc
5 changes: 5 additions & 0 deletions .gitignore
@@ -1,3 +1,8 @@
bazel-*
.bazel
user.bazelrc
.cpcache

/_build
/bin
/graphql_ppx*.exe
Expand Down
20 changes: 20 additions & 0 deletions 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)})
38 changes: 38 additions & 0 deletions 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
25 changes: 25 additions & 0 deletions 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()
35 changes: 35 additions & 0 deletions 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",
]
)
36 changes: 36 additions & 0 deletions 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"}
}
}
112 changes: 112 additions & 0 deletions 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"},
)
8 changes: 8 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions bzl/tools/aliases
@@ -0,0 +1,2 @@
# source me
alias "bl=less `bazel info command_log`"
22 changes: 22 additions & 0 deletions 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
23 changes: 23 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions 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.
32 changes: 32 additions & 0 deletions 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" })
9 changes: 9 additions & 0 deletions 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