Skip to content

Commit 3fc6dad

Browse files
authored
Update Bazel dependencies (#27)
* Update Bazel dependencies Update rules_go, Gazelle and Bazel Go version Add all tests to module BUILD.bazel Ignore MODULE.bazel for now * Makefile: Add OS feature detection Use build mechanism appropriate on host platform Provide cross-compilation options on Linux for macOS and Windows target platforms Remove rpm toolchain dependency on non-rpm targets Update dependency install dialog
1 parent b2fdd83 commit 3fc6dad

File tree

4 files changed

+85
-23
lines changed

4 files changed

+85
-23
lines changed

Makefile

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,79 @@
11

2-
.PHONY: all bazel build clean realclean package package_deb package_rpm
3-
4-
build: bazel
5-
#go build -ldflags "-X github.com/netsec-ethz/bootstrapper/config.versionString="$(./.bazel-build-env | awk '{print $2}')
2+
.PHONY: all bazel bootstrappper build go_build install_deps clean realclean package package_deb package_rpm
3+
4+
build: install_deps bazel
5+
6+
go_build:
7+
@go build -o scion-bootstrapper -ldflags "-X github.com/netsec-ethz/bootstrapper/config.versionString="$$(git describe --tags --dirty --always)
8+
9+
bootstrapper:
10+
@if [ -n "$${OS}" ] ; then \
11+
UNAME_OS="$${OS}"; \
12+
else \
13+
UNAME_OS=$$(uname --kernel-name); \
14+
fi; \
15+
if [ "$${UNAME_OS}" = "Linux" ] ; then \
16+
make -s build; \
17+
elif [ "$${UNAME_OS}" = "Windows_NT" ] ; then \
18+
make.exe -s go_build; \
19+
cp scion-bootstrapper scion-bootstrapper.exe; \
20+
else \
21+
make -s go_build; \
22+
fi;
23+
24+
install_deps:
25+
@if [ -z "$${CC}" ] ; then \
26+
if [ ! -x "$$(command -v gcc)" ]; then \
27+
echo "Cannot find gcc or CC; set the CC environment variable or make sure gcc is on your PATH."; \
28+
else \
29+
exit 0; \
30+
fi; \
31+
else \
32+
exit 0; \
33+
fi; \
34+
apt-get install build-essential 2>/dev/null; \
35+
test $$? -eq 0 || echo "Install build tools?\nsudo apt-get install build-essential" && sudo apt-get install build-essential
636

737
bazel: go_deps.bzl
838
rm -f bin/*
39+
@if [ -z "$${CC}" ] ; then \
40+
if [ ! -x "$$(command -v gcc)" ]; then \
41+
echo "Cannot find gcc or CC; set the CC environment variable or make sure gcc is on your PATH." && exit 1; \
42+
fi; \
43+
fi;
944
./.bazel-build-env
1045
bazel build //:bootstrapper
11-
cp `bazel aquery 'outputs(".*bin/bootstrapper", //:bootstrapper)' --output=text 2>/dev/null | grep "Outputs" | sed -r 's/\s*Outputs: \[(.*)\]/\1/'` bin/
46+
@cp `bazel aquery 'outputs(".*bin/bootstrapper", //:bootstrapper)' --output=text 2>/dev/null | grep "Outputs" | sed -r 's/\s*Outputs: \[(.*)\]/\1/'` bin/
47+
@ln -sf ./bin/bootstrapper ./scion-bootstrapper
1248

13-
all: build test package
49+
all: bootstrapper test package
1450

1551
clean:
1652
bazel clean
17-
rm -f bin/*
53+
rm -f ./bin/*
1854

1955
realclean: clean
2056
bazel clean --expunge
21-
rm ~/.cache/bazel
22-
rm -f go_deps.bzl
57+
rm -f ./MODULE.bazel*
58+
rm -f ./go_deps.bzl
2359

2460
package: package_deb
2561

2662
package_deb: build
63+
@if [ ! -x "$$(command -v python3)" ]; then \
64+
echo "Cannot find python3 on your PATH."; \
65+
apt-get install python3 &>/dev/null; \
66+
test $$? -eq 0 || echo "Install python3?\nsudo apt-get install python3" && sudo apt-get install python3; \
67+
fi;
2768
bazel build //:scion-bootstrapper-deb
2869
cp bazel-bin/scion-bootstrapper_*_*.deb bin/
2970

3071
package_rpm: build
72+
@if [ ! -x "$$(command -v rpmbuild)" ]; then \
73+
echo "Cannot find rpmbuild on your PATH."; \
74+
apt-get install rpm &>/dev/null; \
75+
test $$? -eq 0 || echo "Install rpm toolchain?\nsudo apt-get install rpm" && sudo apt-get install rpm; \
76+
fi;
3177
bazel build //:scion-bootstrapper-rpm
3278
cp bazel-bin/scion-bootstrapper-*.*.rpm bin/
3379

@@ -52,7 +98,16 @@ ifeq (,$(wildcard go_deps.bzl))
5298
$(file > ./go_deps.bzl,$(go_deps_boilerplate))
5399
endif
54100
bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=go_deps.bzl%go_deps -prune
101+
bazel clean --expunge
55102

56103
test: build
57-
bazel test --config=unit --test_output=errors ...
104+
@if [ ! -x "$$(command -v "scion-pki")" ]; then \
105+
echo "Cannot find scion-pki; make sure scion-pki is on your PATH otherwise the tests relying on it will fail."; \
106+
fi;
107+
bazel test --test_output=errors //hinting:go_default_test //fetcher:go_default_test //config:go_default_test
108+
# Do not filter on unit tag for now, as doing so forces all loaded packages
109+
# to satisfy their dependencies, which is not desirable for pkg_rpm
110+
# which forces to have a full rpm toolchain loaded, even when the target
111+
# is not executed. Explicitly list all test targets.
112+
#bazel test --config=unit --test_output=errors ...
58113

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ To build the bootstrapper executable, simply run `make bootstrapper` in the top
5656
In order to build the bootstrapper debian package, we use Bazel.
5757
The service files are in the `./res/packaging/debian/` directory.
5858
You can install Bazel by following the instructions at https://docs.bazel.build/versions/master/install-ubuntu.html
59-
You can then build the package by running `bazel build //:scion-bootstrapper-deb`.
59+
You can then build the package by running `make package_deb`.
6060
When contributing, please run `make all` in order to make sure that all targets build and to run the linter.
6161

6262
Experimental availability is also provided for macOS and Windows. Run `make darwin` or `make windows` to build a

WORKSPACE

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file"
55
# Bazel rules for Golang
66
http_archive(
77
name = "io_bazel_rules_go",
8-
sha256 = "f2dcd210c7095febe54b804bb1cd3a58fe8435a909db2ec04e31542631cf715c",
8+
sha256 = "d93ef02f1e72c82d8bb3d5169519b36167b33cf68c252525e3b9d3d5dd143de7",
99
urls = [
10-
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.31.0/rules_go-v0.31.0.zip",
11-
"https://github.com/bazelbuild/rules_go/releases/download/v0.31.0/rules_go-v0.31.0.zip",
10+
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.49.0/rules_go-v0.49.0.zip",
11+
"https://github.com/bazelbuild/rules_go/releases/download/v0.49.0/rules_go-v0.49.0.zip",
1212
],
1313
)
1414

@@ -18,7 +18,7 @@ go_rules_dependencies()
1818

1919
go_register_toolchains(
2020
nogo = "@//:nogo",
21-
go_version = "1.18",
21+
version = "1.22.7"
2222
)
2323

2424
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
@@ -39,10 +39,10 @@ rules_pkg_dependencies()
3939
# Gazelle
4040
http_archive(
4141
name = "bazel_gazelle",
42-
sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb",
42+
integrity = "sha256-12v3pg/YsFBEQJDfooN6Tq+YKeEWVhjuNdzspcvfWNU=",
4343
urls = [
44-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
45-
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
44+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.37.0/bazel-gazelle-v0.37.0.tar.gz",
45+
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.37.0/bazel-gazelle-v0.37.0.tar.gz",
4646
],
4747
)
4848

hinting/BUILD.bazel

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@io_bazel_rules_go//go:def.bzl", "go_library")
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
22

33
go_library(
44
name = "go_default_library",
@@ -11,6 +11,9 @@ go_library(
1111
"dns.go",
1212
"dns_config_resolv.go",
1313
"dns_config_windows.go",
14+
"dns_search_domain_fallbacks.go",
15+
"dns_search_domain_fallbacks_reverse.go",
16+
"dns_search_domain_fallbacks_whois.go",
1417
"hinting.go",
1518
"ipv6_nd_rad.go",
1619
"mdns.go",
@@ -65,10 +68,6 @@ go_library(
6568
"@com_github_insomniacslk_dhcp//dhcpv4/client4:go_default_library",
6669
"@org_golang_x_sys//unix:go_default_library",
6770
],
68-
"@io_bazel_rules_go//go/platform:nacl": [
69-
"@org_golang_x_net//ipv4:go_default_library",
70-
"@org_golang_x_sys//unix:go_default_library",
71-
],
7271
"@io_bazel_rules_go//go/platform:netbsd": [
7372
"@org_golang_x_net//ipv4:go_default_library",
7473
"@org_golang_x_sys//unix:go_default_library",
@@ -92,3 +91,11 @@ go_library(
9291
"//conditions:default": [],
9392
}),
9493
)
94+
95+
go_test(
96+
name = "go_default_test",
97+
srcs = ["dns_search_domain_fallbacks_test.go"],
98+
embed = [":go_default_library"],
99+
tags = ["unit"],
100+
deps = ["@com_github_stretchr_testify//assert:go_default_library"],
101+
)

0 commit comments

Comments
 (0)