Skip to content

Commit c53053b

Browse files
committed
bazel: migrate to bazel module
1 parent 70da7be commit c53053b

8 files changed

+190
-407
lines changed

.bazelrc

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
common --noenable_bzlmod
2-
31
# ----CONFIG OPTIONS----
42
build --flag_alias=with_bop=//ortools/linear_solver:with_bop
53
build --flag_alias=with_cbc=//ortools/linear_solver:with_cbc
@@ -21,10 +19,19 @@ build --apple_platform_type=macos
2119
# platform.
2220
build --enable_platform_specific_config
2321

24-
build:linux --cxxopt="-std=c++17" --cxxopt=-Wno-sign-compare --host_cxxopt="-std=c++17" --host_cxxopt=-Wno-sign-compare
25-
build:macos --cxxopt="-std=c++17" --cxxopt=-Wno-sign-compare --cxxopt=-mmacos-version-min=10.15 --cxxopt=-Wno-dangling-field --features=-supports_dynamic_linker
22+
# Fix the python version
23+
build --@rules_python//python/config_settings:python_version=3.12
24+
25+
# Per platform parameters.
26+
build:linux --cxxopt="-std=c++17" --cxxopt=-Wno-sign-compare
27+
build:linux --host_cxxopt="-std=c++17" --host_cxxopt=-Wno-sign-compare
28+
29+
build:macos --features=-supports_dynamic_linker
30+
build:macos --cxxopt="-std=c++17" --cxxopt=-Wno-sign-compare --cxxopt=-mmacos-version-min=10.15 --cxxopt=-Wno-dangling-field
2631
build:macos --host_cxxopt="-std=c++17" --host_cxxopt=-Wno-sign-compare --host_cxxopt=-mmacos-version-min=10.15 --host_cxxopt=-Wno-dangling-field
27-
build:windows --cxxopt="/std:c++20" --host_cxxopt="/std:c++20"
32+
33+
build:windows --cxxopt="/std:c++20"
34+
build:windows --host_cxxopt="/std:c++20"
2835

2936
# Enable the runfiles symlink tree on Windows. This makes it possible to build
3037
# the pip package on Windows without an intermediate data-file archive, as the

.github/workflows/amd64_linux_bazel.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ jobs:
4141
sudo apt-get install bazel
4242
- name: Check Bazel
4343
run: bazel version
44-
- name: Change Python in WORKSPACE
45-
run: >
46-
sed
47-
-i
48-
's/\(DEFAULT_PYTHON =\) "3.[0-9]\+"/\1 "${{ matrix.python.version }}"/g'
49-
WORKSPACE
44+
- name: Change Python in .bazelrc
45+
run: |
46+
sed -i -e 's/\(python_version=\)3.[0-9]\+/\1${{ matrix.python.version }}/g' .bazelrc
47+
cat .bazelrc
48+
- name: Change Python in .bazelrc
49+
run: |
50+
sed -i -e 's/\(DEFAULT_PYTHON =\) "3.[0-9]\+"/\1 "${{ matrix.python.version }}"/g' MODULE.bazel
51+
cat MODULE.bazel
5052
- name: Build
5153
run: >
5254
bazel build

.github/workflows/amd64_macos_bazel.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ jobs:
3434
run: python --version
3535
- name: Check Bazel
3636
run: bazel version
37-
- name: Change Python in WORKSPACE
38-
run: >
39-
sed
40-
-i ''
41-
-e 's/\(DEFAULT_PYTHON =\) "3.[0-9]*"/\1 "${{ matrix.python.version }}"/g'
42-
WORKSPACE
37+
- name: Change Python in .bazelrc
38+
run: |
39+
sed -i '' -e 's/\(python_version=\)3.[0-9]*/\1${{ matrix.python.version }}/g' .bazelrc
40+
cat .bazelrc
41+
- name: Change Python in MODULE.bazel
42+
run: |
43+
sed -i '' -e 's/\(DEFAULT_PYTHON =\) "3.[0-9]*"/\1 "${{ matrix.python.version }}"/g' MODULE.bazel
44+
cat MODULE.bazel
4345
- name: Build
4446
run: >
4547
bazel build

.github/workflows/amd64_windows_bazel.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
matrix:
1111
runner: [windows-2022]
1212
python: [
13-
{version: '3.10'},
14-
{version: '3.11'},
13+
# {version: '3.10'},
14+
# {version: '3.11'},
1515
{version: '3.12'},
16-
{version: '3.13'},
16+
# {version: '3.13'},
1717
]
1818
fail-fast: false # Don't cancel all jobs if one fails.
1919
name: ${{ matrix.runner }} • Bazel • Python-${{ matrix.python.version }}

.github/workflows/arm64_macos_bazel.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ jobs:
3434
run: python --version
3535
- name: Check Bazel
3636
run: bazel version
37-
- name: Change Python in WORKSPACE
38-
run: >
39-
sed
40-
-i ''
41-
-e 's/\(DEFAULT_PYTHON =\) "3.[0-9]*"/\1 "${{ matrix.python.version }}"/g'
42-
WORKSPACE
37+
- name: Change Python in .bazelrc
38+
run: |
39+
sed -i '' -e 's/\(python_version=\)3.[0-9]*/\1${{ matrix.python.version }}/g' .bazelrc
40+
cat .bazelrc
41+
- name: Change Python in MODULE.bazel
42+
run: |
43+
sed -i '' -e 's/\(DEFAULT_PYTHON =\) "3.[0-9]*"/\1 "${{ matrix.python.version }}"/g' MODULE.bazel
44+
cat MODULE.bazel
4345
- name: Build
4446
run: >
4547
bazel build

MODULE.bazel

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
###############################################################################
2+
# Bazel now uses Bzlmod by default to manage external dependencies.
3+
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
4+
#
5+
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
6+
###############################################################################
7+
8+
OR_TOOLS_VERSION = "10.0.0"
9+
10+
module(
11+
name = "or-tools",
12+
repo_name = "com_google_ortools",
13+
version = OR_TOOLS_VERSION,
14+
)
15+
16+
bazel_dep(name = "abseil-cpp", version = "20240722.0", repo_name = "com_google_absl")
17+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
18+
bazel_dep(name = "contrib_rules_jvm", version = "0.27.0")
19+
bazel_dep(name = "eigen", version = "3.4.0.bcr.1")
20+
bazel_dep(name = "gazelle", version = "0.39.1", repo_name = "bazel_gazelle")
21+
bazel_dep(name = "glpk", version = "5.0.bcr.1")
22+
bazel_dep(name = "google_benchmark", version = "1.8.5", repo_name = "com_google_benchmark")
23+
bazel_dep(name = "googletest", version = "1.15.2", repo_name = "com_google_googletest")
24+
bazel_dep(name = "highs", version = "1.8.0")
25+
bazel_dep(name = "platforms", version = "0.0.10")
26+
bazel_dep(name = "protobuf", version = "28.3", repo_name = "com_google_protobuf")
27+
bazel_dep(name = "pybind11_abseil", version = "202402.0", repo_name = "org_pybind11_abseil")
28+
bazel_dep(name = "pybind11_bazel", version = "2.13.6")
29+
bazel_dep(name = "pybind11_protobuf", version = "0.0.0-20240524-1d7a729")
30+
bazel_dep(name = "re2", version = "2024-07-02", repo_name = "com_google_re2")
31+
bazel_dep(name = "rules_cc", version = "0.0.10")
32+
bazel_dep(name = "rules_go", version = "0.50.1", repo_name = "io_bazel_rules_go")
33+
bazel_dep(name = "rules_java", version = "7.12.2")
34+
bazel_dep(name = "rules_jvm_external", version = "6.4")
35+
bazel_dep(name = "rules_license", version = "1.0.0")
36+
bazel_dep(name = "rules_proto", version = "6.0.2")
37+
bazel_dep(name = "rules_python", version = "0.37.2")
38+
bazel_dep(name = "scip", version = "8.1.0")
39+
bazel_dep(name = "swig", version = "4.2.0")
40+
bazel_dep(name = "zlib", version = "1.3.1.bcr.3")
41+
42+
git_override(
43+
module_name = "pybind11_abseil",
44+
commit = "70f8b693b3b70573ca785ef62d9f48054f45d786",
45+
patches = ["//patches:pybind11_abseil.patch"],
46+
patch_strip = 1,
47+
remote = "https://github.com/pybind/pybind11_abseil.git",
48+
)
49+
50+
SUPPORTED_PYTHON_VERSIONS = [
51+
"3.8",
52+
"3.9",
53+
"3.10",
54+
"3.11",
55+
"3.12",
56+
"3.13",
57+
]
58+
59+
DEFAULT_PYTHON = "3.11"
60+
61+
python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency=True)
62+
[
63+
python.toolchain(
64+
ignore_root_user_error = True, # needed for CI
65+
python_version = version,
66+
is_default = version == DEFAULT_PYTHON,
67+
)
68+
for version in SUPPORTED_PYTHON_VERSIONS
69+
]
70+
71+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
72+
73+
[
74+
pip.parse(
75+
hub_name = "ortools_pip_deps",
76+
python_version = python_version,
77+
requirements_lock = "//bazel:ortools_requirements.txt",
78+
)
79+
for python_version in SUPPORTED_PYTHON_VERSIONS
80+
]
81+
82+
[
83+
pip.parse(
84+
hub_name = "ortools_notebook_deps",
85+
python_version = python_version,
86+
requirements_lock = "//bazel:notebook_requirements.txt",
87+
)
88+
for python_version in SUPPORTED_PYTHON_VERSIONS
89+
]
90+
91+
use_repo(pip, pip_deps = "ortools_pip_deps")
92+
use_repo(pip, "ortools_notebook_deps")
93+
94+
JUNIT_PLATFORM_VERSION = "1.9.2"
95+
96+
JUNIT_JUPITER_VERSION = "5.9.2"
97+
98+
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
99+
maven.install(
100+
artifacts = [
101+
"net.java.dev.jna:jna:5.14.0",
102+
"com.google.truth:truth:0.32",
103+
"org.junit.platform:junit-platform-launcher:%s" % JUNIT_PLATFORM_VERSION,
104+
"org.junit.platform:junit-platform-reporting:%s" % JUNIT_PLATFORM_VERSION,
105+
"org.junit.jupiter:junit-jupiter-api:%s" % JUNIT_JUPITER_VERSION,
106+
"org.junit.jupiter:junit-jupiter-params:%s" % JUNIT_JUPITER_VERSION,
107+
"org.junit.jupiter:junit-jupiter-engine:%s" % JUNIT_JUPITER_VERSION,
108+
],
109+
repositories = [
110+
"https://repo1.maven.org/maven2",
111+
],
112+
)
113+
use_repo(maven, "maven")
114+
115+
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
116+
go_sdk.download(version = "1.22.4")
117+
118+
go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
119+
go_deps.module(
120+
path = "github.com/golang/glog",
121+
sum = "h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY=",
122+
version = "v1.2.2",
123+
)
124+
go_deps.module(
125+
path = "github.com/golang/protobuf",
126+
sum = "h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=",
127+
version = "v1.5.0",
128+
)
129+
go_deps.module(
130+
path = "github.com/google/go-cmp",
131+
sum = "h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=",
132+
version = "v0.6.0",
133+
)
134+
go_deps.module(
135+
path = "google.golang.org/protobuf",
136+
sum = "h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=",
137+
version = "v1.34.2",
138+
)
139+
go_deps.module(
140+
path = "golang.org/x/xerrors",
141+
sum = "h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=",
142+
version = "v0.0.0-20191204190536-9bdfabe68543",
143+
)
144+
use_repo(
145+
go_deps,
146+
"com_github_golang_glog",
147+
"com_github_golang_protobuf",
148+
"com_github_google_go_cmp",
149+
"org_golang_google_protobuf",
150+
"org_golang_x_xerrors",
151+
)

0 commit comments

Comments
 (0)