-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMODULE.bazel
168 lines (143 loc) · 5.41 KB
/
MODULE.bazel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
module(
name = "bazel-diesel-postgres",
version = "0.1.0",
)
###############################################################################
# BAZE DEPENDENCIES # https://registry.bazel.build/
###############################################################################
# https://github.com/bazelbuild/bazel-skylib/releases/
bazel_dep(name = "bazel_skylib", version = "1.7.1")
# https://github.com/bazelbuild/rules_rust/releases
bazel_dep(name = "rules_rust", version = "0.50.1")
# Rules for cross compilation
# https://github.com/bazel-contrib/toolchains_llvm
bazel_dep(name = "toolchains_llvm", version = "1.1.2")
# https://github.com/bazelbuild/platforms/releases
bazel_dep(name = "platforms", version = "0.0.10")
# https://github.com/bazel-contrib/musl-toolchain/releases
bazel_dep(name = "toolchains_musl", version = "0.1.20", dev_dependency = True)
# https://github.com/brainhivenl/libpq
bazel_dep(name = "libpq", version = "0.0.1")
git_override(
module_name = "libpq",
commit = "ebdeb0cc9b8e051779e00b37ec0f93fab9ba8dd8",
remote = "https://github.com/brainhivenl/libpq",
)
# https://github.com/bazelbuild/bazel/blob/master/tools/build_defs/repo/http.bzl
http_archive = use_repo_rule("@bazel_tools//:http.bzl", "http_archive")
###############################################################################
# LLVM TOOLCHAIN
###############################################################################
# Rust cross compilation needs a C/C++ toolchain with sysroot to compile C dependencies.
_BUILD_FILE_CONTENT = """
filegroup(
name = "{name}",
srcs = glob(["*/**"]),
visibility = ["//visibility:public"],
)
"""
# Download sysroot
# https://commondatastorage.googleapis.com/chrome-linux-sysroot/
http_archive(
name = "org_chromium_sysroot_linux_x64",
build_file_content = _BUILD_FILE_CONTENT.format(name = "sysroot"),
sha256 = "f6b758d880a6df264e2581788741623320d548508f07ffc2ae6a29d0c13d647d",
urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/2e7ada854015a4cc60fc812112d261af44213ed0/debian_bullseye_amd64_sysroot.tar.xz"],
)
http_archive(
name = "org_chromium_sysroot_linux_aarch64",
build_file_content = _BUILD_FILE_CONTENT.format(name = "sysroot"),
sha256 = "902d1a40a5fd8c3764a36c8d377af5945a92e3d264c6252855bda4d7ef81d3df",
urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/41a6c8dec4c4304d6509e30cbaf9218dffb4438e/debian_bullseye_arm64_sysroot.tar.xz"],
)
# LLVM setup
# https://github.com/bazel-contrib/toolchains_llvm/tree/0d302de75f6ace071ac616fb274481eedcc20e5a?tab=readme-ov-file#sysroots
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
# LLVM Versions and platforms
# https://github.com/bazel-contrib/toolchains_llvm/blob/master/toolchain/internal/llvm_distributions.bzl
LLVM_VERSIONS = {
"": "16.0.0",
"darwin-aarch64": "16.0.3",
"darwin-x86_64": "15.0.7",
}
# Host LLVM toolchain.
llvm.toolchain(
name = "llvm_toolchain",
llvm_versions = LLVM_VERSIONS,
)
use_repo(llvm, "llvm_toolchain", "llvm_toolchain_llvm")
# Target X86 LLVM Toolchain with sysroot.
# https://github.com/bazel-contrib/toolchains_llvm/blob/master/tests/WORKSPACE.bzlmod
llvm.toolchain(
name = "llvm_toolchain_x86_with_sysroot",
llvm_versions = LLVM_VERSIONS,
)
llvm.sysroot(
name = "llvm_toolchain_x86_with_sysroot",
label = "@@org_chromium_sysroot_linux_x64//:sysroot",
targets = ["linux-x86_64"],
)
use_repo(llvm, "llvm_toolchain_x86_with_sysroot")
# Target ARM (aarch64) LLVM Toolchain with sysroot.
# https://github.com/bazelbuild/rules_rust/blob/main/examples/bzlmod/cross_compile/WORKSPACE.bzlmod
llvm.toolchain(
name = "llvm_toolchain_aarch64_with_sysroot",
llvm_versions = LLVM_VERSIONS,
)
llvm.sysroot(
name = "llvm_toolchain_aarch64_with_sysroot",
label = "@@org_chromium_sysroot_linux_aarch64//:sysroot",
targets = ["linux-aarch64"],
)
use_repo(llvm, "llvm_toolchain_aarch64_with_sysroot")
# Register all LLVM toolchains
register_toolchains("@llvm_toolchain//:all")
###############################################################################
# RUST TOOLCHAIN
###############################################################################
RUST_EDITION = "2021" # NOTE: 2024 is released in 1.86.0
RUST_VERSION = "1.81.0"
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = RUST_EDITION,
extra_target_triples = [
"aarch64-unknown-linux-gnu",
"x86_64-unknown-linux-gnu",
],
versions = [RUST_VERSION],
)
use_repo(rust, "rust_toolchains")
register_toolchains("@rust_toolchains//:all")
###############################################################################
# RUST SYSTEM DEPENDENCIES
###############################################################################
crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate", isolate = True)
# External crates
crate.spec(
default_features = False,
features = [
"postgres",
"r2d2",
],
package = "diesel",
version = "2.2.2",
)
crate.spec(
default_features = False,
features = ["postgres"],
package = "diesel_migrations",
version = "2.2.0",
)
crate.from_specs()
use_repo(crate, "crates")
crate.annotation(
crate = "pq-sys",
build_script_env = {
"PQ_LIB_STATIC": "1",
},
rustc_flags = [
"-L",
"$(BINDIR)/@@//alias:libpq",
],
deps = ["@@//alias:libpq"],
)