Skip to content

Commit

Permalink
Merge pull request #118 from ljessendk/bzlmod
Browse files Browse the repository at this point in the history
  • Loading branch information
solsjo authored Oct 13, 2024
2 parents f9e1532 + fd96c9d commit 227b02f
Show file tree
Hide file tree
Showing 24 changed files with 544 additions and 296 deletions.
2 changes: 2 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
example/bzlmod
example/bzlmod_use_texlive_deps
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.2
7.3.1
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- uses: thompsonja/[email protected]
with:
buildifier_version: 5.1.0
buildifier_version: v7.3.1
warnings: all

test:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.ijwb
.nfs*
/bazel-*
/MODULE.bazel.lock
91 changes: 51 additions & 40 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
load(":toolchain.bzl", "latex_toolchain")

exports_files([
Expand All @@ -10,13 +11,16 @@ toolchain_type(
visibility = ["//visibility:public"],
)

latex_toolchain(
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:freebsd",
],
platform = "amd64-freebsd",
)
# This toolchain seems to be missing the 'biber' binary, causing Bazel to produce the following error
# "no such target '@@texlive_bin__amd64-freebsd//:biber': target 'biber' not declared in package ''"
# Disabled for now
# latex_toolchain(
# exec_compatible_with = [
# "@platforms//cpu:x86_64",
# "@platforms//os:freebsd",
# ],
# platform = "amd64-freebsd",
# )

latex_toolchain(
name = "latex_toolchain_aarch64-darwin",
Expand Down Expand Up @@ -47,46 +51,46 @@ latex_toolchain(
filegroup(
name = "core_dependencies",
srcs = [
"@texlive_extra__tlpkg__TeXLive",
"@texlive_texmf__texmf-dist__fonts__enc__dvips__base",
"@texlive_texmf__texmf-dist__fonts__enc__dvips__cm-super",
"@texlive_texmf__texmf-dist__fonts__enc__dvips__lm",
"@texlive_texmf__texmf-dist__fonts__opentype__public__lm",
"@texlive_texmf__texmf-dist__fonts__tfm__public__cm",
"@texlive_texmf__texmf-dist__fonts__tfm__public__latex-fonts",
"@texlive_texmf__texmf-dist__fonts__tfm__public__lm",
"@texlive_texmf__texmf-dist__fonts__type1__public__amsfonts__cm",
"@texlive_texmf__texmf-dist__fonts__type1__public__cm-super",
"@texlive_texmf__texmf-dist__fonts__type1__public__lm",
"@texlive_texmf__texmf-dist__scripts__texlive",
"@texlive_texmf__texmf-dist__tex__generic__config",
"@texlive_texmf__texmf-dist__tex__generic__hyphen",
"@texlive_texmf__texmf-dist__tex__generic__iftex",
"@texlive_texmf__texmf-dist__tex__generic__infwarerr",
"@texlive_texmf__texmf-dist__tex__generic__kvsetkeys",
"@texlive_texmf__texmf-dist__tex__generic__ltxcmds",
"@texlive_texmf__texmf-dist__tex__generic__pdftexcmds",
"@texlive_texmf__texmf-dist__tex__generic__unicode-data",
"@texlive_texmf__texmf-dist__tex__latex__base",
"@texlive_texmf__texmf-dist__tex__latex__kvoptions",
"@texlive_texmf__texmf-dist__tex__latex__l3backend",
"@texlive_texmf__texmf-dist__tex__latex__l3kernel",
"@texlive_texmf__texmf-dist__tex__latex__l3packages__xparse",
"@texlive_texmf__texmf-dist__tex__latex__latexconfig",
"@texlive_texmf__texmf-dist__tex__latex__lm",
"@texlive_texmf__texmf-dist__tex__luatex__lua-uni-algos",
"@texlive_texmf__texmf-dist__tex__luatex__lualibs",
"@texlive_texmf__texmf-dist__tex__luatex__luaotfload",
"@texlive_texmf__texmf-dist__web2c",
"@bazel_latex_texlive//:texlive_extra__tlpkg__TeXLive",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__fonts__enc__dvips__base",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__fonts__enc__dvips__cm-super",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__fonts__enc__dvips__lm",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__fonts__opentype__public__lm",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__fonts__tfm__public__cm",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__fonts__tfm__public__latex-fonts",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__fonts__tfm__public__lm",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__fonts__type1__public__amsfonts__cm",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__fonts__type1__public__cm-super",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__fonts__type1__public__lm",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__scripts__texlive",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__generic__config",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__generic__hyphen",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__generic__iftex",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__generic__infwarerr",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__generic__kvsetkeys",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__generic__ltxcmds",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__generic__pdftexcmds",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__generic__unicode-data",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__latex__base",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__latex__kvoptions",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__latex__l3backend",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__latex__l3kernel",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__latex__l3packages__xparse",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__latex__latexconfig",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__latex__lm",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__luatex__lua-uni-algos",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__luatex__lualibs",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__luatex__luaotfload",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__web2c",
],
visibility = ["//visibility:public"],
)

filegroup(
name = "ghostscript_dependencies",
srcs = [
"@texlive_texmf__texmf-dist__dvips__base",
"@texlive_texmf__texmf-dist__dvips__l3backend",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__dvips__base",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__dvips__l3backend",
],
visibility = ["//visibility:public"],
)
Expand All @@ -96,3 +100,10 @@ py_binary(
srcs = ["dvi_sub.py"],
visibility = ["//visibility:public"],
)

compile_pip_requirements(
name = "requirements",
src = "requirements.in",
requirements_txt = "requirements_lock.txt",
tags = ["manual"],
)
82 changes: 82 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""
"""

module(
name = "bazel_latex",
version = "1.2.2",
compatibility_level = 0,
repo_name = "bazel_latex",
)

bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_foreign_cc", version = "0.12.0")
bazel_dep(name = "rules_python", version = "0.36.0")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "py_deps",
python_version = "3.11",
requirements_lock = "//:requirements_lock.txt",
)
use_repo(pip, "py_deps")

register_toolchains(
"//:latex_toolchain_aarch64-darwin",
# The latex_toolchain_amd64-freebsd seems broken, see comment in BUILD.bazel, so disabled for now
#"@bazel_latex//:latex_toolchain_amd64-freebsd",
"//:latex_toolchain_x86_64-darwin",
"//:latex_toolchain_x86_64-linux",
)

texlive_repositories = use_extension("//:extensions.bzl", "texlive_repositories")
texlive_repositories.install()
use_repo(
texlive_repositories,
"bazel_latex_texlive",
"texlive_bin__aarch64-linux",
"texlive_bin__amd64-freebsd",
"texlive_bin__amd64-netbsd",
"texlive_bin__armhf-linux",
"texlive_bin__i386-cygwin",
"texlive_bin__i386-freebsd",
"texlive_bin__i386-linux",
"texlive_bin__i386-netbsd",
"texlive_bin__i386-solaris",
"texlive_bin__universal-darwin",
"texlive_bin__win32",
"texlive_bin__x86_64-cygwin",
"texlive_bin__x86_64-darwinlegacy",
"texlive_bin__x86_64-linux",
"texlive_bin__x86_64-linuxmusl",
"texlive_bin__x86_64-solaris",
"texlive_texmf__texmf-dist__scripts__texlive",
)

module_repositories = use_extension("//:repositories.bzl", "module_repositories")
use_repo(
module_repositories,
"bazel_latex_latexrun",
"ghost_script_source",
)

# mac os shared lib was difficult to build via foreign rules so as a temporary
# solution we provide it as a precompiled artifact.
# Consider making it available via bazel_latex binaries repo instead
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "ghostscript_macos",
build_file_content = """
filegroup(
name = "libgs_macos",
srcs = glob(["*/*"]),
target_compatible_with = ["@platforms//os:osx"],
visibility = ["//visibility:public"],
)
""",
sha256 = "56b480ebdf34000eac4a29e108ce6384858941d892fd69e604d90585aaae4c94",
urls = [
"https://github.com/solsjo/rules_latex_deps/releases/download/v0.9.4/rules_latex_deps_macos-latest.zip",
],
)
23 changes: 16 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ http_archive(

register_toolchains(
"@bazel_latex//:latex_toolchain_aarch64-darwin",
"@bazel_latex//:latex_toolchain_amd64-freebsd",
# The latex_toolchain_amd64-freebsd seems broken, see comment in BUILD.bazel, so disabled for now
#"@bazel_latex//:latex_toolchain_amd64-freebsd",
"@bazel_latex//:latex_toolchain_x86_64-darwin",
"@bazel_latex//:latex_toolchain_x86_64-linux",
)
Expand Down Expand Up @@ -53,14 +54,22 @@ filegroup(

http_archive(
name = "rules_python",
sha256 = "a30abdfc7126d497a7698c29c46ea9901c6392d6ed315171a6df5ce433aa4502",
strip_prefix = "rules_python-0.6.0",
url = "https://github.com/bazelbuild/rules_python/archive/0.6.0.tar.gz",
sha256 = "ca77768989a7f311186a29747e3e95c936a41dffac779aff6b443db22290d913",
strip_prefix = "rules_python-0.36.0",
url = "https://github.com/bazelbuild/rules_python/archive/0.36.0.tar.gz",
)

load("@rules_python//python:pip.bzl", "pip_install")
load("@rules_python//python:repositories.bzl", "py_repositories")

pip_install(
py_repositories()

load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "py_deps",
requirements = "//:requirements.txt",
requirements_lock = "//:requirements_lock.txt",
)

load("@py_deps//:requirements.bzl", "install_deps")

install_deps()
Empty file added WORKSPACE.bzlmod
Empty file.
8 changes: 4 additions & 4 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ latex_document(
srcs = glob([
"chapters/*.tex",
]) + [
"@bazel_latex//packages:biblatex",
"references.bib",
"//example/example_class:example_class",
"//example/example_class",
"@bazel_latex//packages:biblatex",
],
bib_tool = "biber", # Is the default
main = "my_report.tex",
Expand All @@ -21,9 +21,9 @@ latex_document(
srcs = glob([
"chapters/*.tex",
]) + [
"@bazel_latex//packages:biblatex",
"references.bib",
"//example/example_class:example_class",
"//example/example_class",
"@bazel_latex//packages:biblatex",
],
format = "dvi",
main = "my_report.tex",
Expand Down
2 changes: 2 additions & 0 deletions example/bzlmod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bazel-*
/MODULE.bazel.lock
8 changes: 8 additions & 0 deletions example/bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@bazel_latex//:latex.bzl", "latex_document")

latex_document(
name = "my_document",
srcs = [],
main = "my_document.tex",
visibility = ["//visibility:public"],
)
13 changes: 13 additions & 0 deletions example/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Simple bzlmod example
"""

module(
name = "bazel_latex_example_bzlmod",
)

bazel_dep(name = "bazel_latex")
local_path_override(
module_name = "bazel_latex",
path = "../..",
)
5 changes: 5 additions & 0 deletions example/bzlmod/my_document.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\documentclass{article}
\begin{document}
\section{Hello world}
Test
\end{document}
2 changes: 2 additions & 0 deletions example/bzlmod_use_texlive_deps/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bazel-*
/MODULE.bazel.lock
10 changes: 10 additions & 0 deletions example/bzlmod_use_texlive_deps/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@bazel_latex//:latex.bzl", "latex_document")

latex_document(
name = "my_document",
srcs = [
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__latex__multirow",
],
main = "my_document.tex",
visibility = ["//visibility:public"],
)
20 changes: 20 additions & 0 deletions example/bzlmod_use_texlive_deps/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Simple example that shows how to import the 'bazel_latex_texlive' proxy
"""

module(
name = "bazel_latex_example_bzlmod_use_texlive_deps",
)

bazel_dep(name = "bazel_latex")
local_path_override(
module_name = "bazel_latex",
path = "../..",
)

texlive_repositories = use_extension("@bazel_latex//:extensions.bzl", "texlive_repositories")
texlive_repositories.install()
use_repo(
texlive_repositories,
"bazel_latex_texlive",
)
7 changes: 7 additions & 0 deletions example/bzlmod_use_texlive_deps/my_document.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|}
\multirow{2}{*}{1}\\
\end{tabular}
\end{document}
2 changes: 1 addition & 1 deletion example/example_class/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ filegroup(
name = "example_class",
srcs = [
"example_class.cls",
"@texlive_texmf__texmf-dist__tex__latex__xcolor",
"@bazel_latex_texlive//:texlive_texmf__texmf-dist__tex__latex__xcolor",
],
visibility = ["//visibility:public"],
)
19 changes: 19 additions & 0 deletions extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Extensions for fetching texlive packages
"""

load("@bazel_latex//:repositories.bzl", "latex_texlive_repositories")
load(
"@bazel_latex//:texlive_2022_repos.bzl",
"TEXLIVE_VERSION_2022",
)

def _texlive_repositories_impl(mctx):
for install in mctx.modules[0].tags.install:
latex_texlive_repositories(install.version)
return mctx.extension_metadata(reproducible = True)

texlive_repositories = module_extension(
implementation = _texlive_repositories_impl,
tag_classes = {"install": tag_class(attrs = {"version": attr.string(default = TEXLIVE_VERSION_2022)})},
)
Loading

0 comments on commit 227b02f

Please sign in to comment.