forked from scionproto/scion
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dist: build openwrt packages (scionproto#4464)
The method is the following: * Add the prebuild openwrt SDKs for the desired target platform as an http_archive dependency. * Slap a BUILD.bazel file on top of the SDK so bazel can make it do two things: * Configure a bazel toolchain around the compiler suite embedded in the SDK (musl-gcc/musl-libc). * Make one openwrt package for each SCION component (the pieces are provided by the SCION main workspace). * Declare a platform for each supported openwrt target. * Bind each openwrt toolchain to its matching platform. * Add rules to produce ipk packages for scion components (they just reference and copy the packages produced by the openwrt workspace). * Use multiplatform_filegroup() to transition these packages to each supported openwrt platform. * Add a Make target, dist-openwrt, to build the openwrt file group. That results in the following chain of dependencies for one given component and the amd64 target: => Want openwrt => build openwrt_amd64 (among others, if any) => build "component.ipk for openwrt_amd64" => copy "component.ipk for openwrt_amd64" from @external/openwrtSDK_x86_64 => @external/openwrtSDK_x86_64 obtains "component exec for openwrt_amd64" from @scion, then embed in component.ipk package. => @scion builds component with the openwrt_amd64 toolchain Embellishments: * Optionally generate versioned file names for installables. That removes the need for renaming the files after the build. * Added coremark to our build (and as an openwrt package). The intent is to use it in benchmarking as a rough cpu power metric. * Executable compression when packaging for openwrt, as these devices can be storage constrained and Go executables are huge. Unfortunately there's not much I can do for the in-ram size yet. <!-- Reviewable:start --> - - - This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/scionproto/scion/4464) <!-- Reviewable:end -->
- Loading branch information
1 parent
c5a8e6f
commit a561dbe
Showing
51 changed files
with
4,677 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
load(":package.bzl", "scion_pkg_deb") | ||
load(":package.bzl", "scion_pkg_ipk") | ||
load(":platform.bzl", "multiplatform_filegroup") | ||
load(":git_version.bzl", "git_version") | ||
|
||
DEB_PLATFORMS = [ | ||
"@io_bazel_rules_go//go/toolchain:linux_amd64", | ||
"@io_bazel_rules_go//go/toolchain:linux_arm64", | ||
"@io_bazel_rules_go//go/toolchain:linux_386", | ||
"@io_bazel_rules_go//go/toolchain:linux_arm", | ||
] | ||
|
||
# TODO([email protected]): | ||
# For now only a single openwrt platform can be in this list. If we allow several, they get | ||
# built in parallel, which breaks on non-reentrant openwrt makefiles. For a single platform | ||
# things work because we force the packages to be build serialy by making them depend on | ||
# each other. | ||
OPENWRT_PLATFORMS = [ | ||
"@//dist/openwrt:openwrt_amd64", | ||
] | ||
|
||
# Some files that the openwrt build consumes directly. | ||
exports_files( | ||
[ | ||
"conffiles/gateway.toml", | ||
"conffiles/gateway.json", | ||
"conffiles/daemon.toml", | ||
"conffiles/dispatcher.toml", | ||
|
||
# Directory itself. Indicates the common root of config files. | ||
"conffiles", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
git_version( | ||
name = "git_version", | ||
tags = ["manual"], | ||
visibility = ["//visibility:private"], | ||
visibility = ["@openwrt_x86_64_SDK//:__subpackages__"], | ||
) | ||
|
||
scion_pkg_deb( | ||
|
@@ -57,7 +88,7 @@ scion_pkg_deb( | |
|
||
scion_pkg_deb( | ||
name = "daemon_deb", | ||
configs = ["conffiles/sciond.toml"], | ||
configs = ["conffiles/daemon.toml"], | ||
depends = [ | ||
"adduser", | ||
], | ||
|
@@ -74,8 +105,8 @@ scion_pkg_deb( | |
scion_pkg_deb( | ||
name = "gateway_deb", | ||
configs = [ | ||
"conffiles/sig.json", | ||
"conffiles/sig.toml", | ||
"conffiles/gateway.json", | ||
"conffiles/gateway.toml", | ||
], | ||
depends = [ | ||
"adduser", | ||
|
@@ -117,5 +148,72 @@ multiplatform_filegroup( | |
"router_deb", | ||
"tools_deb", | ||
], | ||
target_platforms = DEB_PLATFORMS, | ||
visibility = ["//dist:__subpackages__"], | ||
) | ||
|
||
scion_pkg_ipk( | ||
name = "persistdbs_ipk", | ||
) | ||
|
||
scion_pkg_ipk( | ||
name = "router_ipk", | ||
) | ||
|
||
scion_pkg_ipk( | ||
name = "gateway_ipk", | ||
) | ||
|
||
scion_pkg_ipk( | ||
name = "control_ipk", | ||
) | ||
|
||
scion_pkg_ipk( | ||
name = "dispatcher_ipk", | ||
) | ||
|
||
scion_pkg_ipk( | ||
name = "daemon_ipk", | ||
) | ||
|
||
scion_pkg_ipk( | ||
name = "tools_ipk", | ||
) | ||
|
||
scion_pkg_ipk( | ||
name = "coremark_ipk", | ||
) | ||
|
||
scion_pkg_ipk( | ||
name = "testconfig_ipk", | ||
) | ||
|
||
# multiplatform_filegroup creates two targets: <name> and <name>_all. | ||
# <name> means "local platform". | ||
# So "build //dist/openwrt" means "make me ipk packages for the local platform only. It wont work, | ||
# unles you happen to be building on an openwrt system (really?). | ||
# What you really want is "build //dist/openwrt_all". | ||
multiplatform_filegroup( | ||
name = "openwrt", | ||
srcs = [ | ||
"control_ipk", | ||
"daemon_ipk", | ||
"dispatcher_ipk", | ||
"gateway_ipk", | ||
"persistdbs_ipk", | ||
"router_ipk", | ||
"tools_ipk", | ||
], | ||
target_platforms = OPENWRT_PLATFORMS, | ||
visibility = ["//dist:__subpackages__"], | ||
) | ||
|
||
multiplatform_filegroup( | ||
name = "openwrt_testing", | ||
srcs = [ | ||
"coremark_ipk", | ||
"testconfig_ipk", | ||
], | ||
target_platforms = OPENWRT_PLATFORMS, | ||
visibility = ["//dist:__subpackages__"], | ||
) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# This BUILD file only takes care of hooking the assets derived | ||
# from the openwrt SDK into the SCION bazel build. | ||
# | ||
# These assets are: | ||
# * a cross-compilation toolchain that targets openwrt_<arch> (i.e. links with musl-libc). | ||
# * openwrt (ipk) packaging of scion binaries built with the above. | ||
# | ||
# Turning these assets into bazel reeferencable dependencies happens in the context of the external | ||
# src tree openwrt_<target>_SDK, which receives its own buildfile (BUILD.external.bazel, installed there by | ||
# the http_archive target "openwrt_<target>_SDK" in //WORKSPACE). | ||
|
||
# Some files that our openwrt build needs. | ||
exports_files( | ||
[ | ||
# Gear to drive the make-based openwrt package build process. | ||
"BUILD.external.bazel", | ||
"endian_h.patch", | ||
"package_makefile.tpl", | ||
|
||
# init.d start/stop files. | ||
"initds/router", | ||
"initds/gateway", | ||
"initds/control", | ||
"initds/daemon", | ||
"initds/dispatcher", | ||
"initds/persistdbs", | ||
|
||
# Directory itself. Indicates the common root of config files. | ||
"test_configs", | ||
|
||
# Minimal configuration for testing. | ||
"test_configs/topology.json", | ||
"test_configs/keys/master0.key", | ||
"test_configs/keys/master1.key", | ||
"test_configs/router.toml", | ||
"test_configs/control.toml", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
# Plumb the musl toolchain of the openwrt SDK as a toolchain we can use here to build SCION | ||
# components. | ||
constraint_value( | ||
name = "musl_libc", | ||
constraint_setting = "@bazel_tools//tools/cpp:cc_compiler", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
toolchain( | ||
name = "x86_64_openwrt_toolchain", | ||
exec_compatible_with = [ | ||
"@platforms//cpu:x86_64", | ||
"@platforms//os:linux", | ||
], | ||
target_compatible_with = [ | ||
"@platforms//cpu:x86_64", | ||
"@platforms//os:linux", | ||
":musl_libc", | ||
], | ||
toolchain = "@openwrt_x86_64_SDK//:x86_64_musl", | ||
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", | ||
) | ||
|
||
platform( | ||
name = "openwrt_amd64", | ||
constraint_values = [ | ||
"@platforms//cpu:x86_64", | ||
"@platforms//os:linux", | ||
":musl_libc", | ||
], | ||
visibility = ["//dist:__subpackages__"], | ||
) |
Oops, something went wrong.