Lorenz Brun | 0de1893 | 2021-03-11 00:36:48 +0100 | [diff] [blame^] | 1 | # Copyright 2020 The Monogon Project Authors. |
| 2 | # |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | load("@rules_cc//cc:defs.bzl", "cc_library") |
| 18 | load("@dev_source_monogon//build/utils:template_file.bzl", "template_file") |
| 19 | |
| 20 | genrule( |
| 21 | name = "config-h", |
| 22 | outs = ["configure.h"], |
| 23 | cmd = "echo \"#define HAVE_LINUX_SECCOMP_H 1\" > \"$@\"", |
| 24 | visibility = ["//visibility:public"], |
| 25 | ) |
| 26 | |
| 27 | genrule( |
| 28 | name = "syscalls-tables", |
| 29 | srcs = [ |
| 30 | "src/syscalls.perf.template", |
| 31 | "src/syscalls.csv", |
| 32 | ], |
| 33 | outs = ["syscalls.perf.c"], |
| 34 | cmd = """ |
| 35 | # From src/arch-gperf-generate, modified to not write over source files |
| 36 | grep -v '^#' $(location src/syscalls.csv) | nl -ba -s, -v0 | \ |
| 37 | sed -e 's/^[[:space:]]\\+\\([0-9]\\+\\),\\([^,]\\+\\),\\(.*\\)/\\2,\\1,\\3/' \ |
| 38 | -e ':repeat; {s|\\([^,]\\+\\)\\(.*\\)[^_]PNR|\\1\\2,__PNR_\\1|g;}; t repeat' \ |
| 39 | > "$(@D)/syscalls_tmp.csv" |
| 40 | |
| 41 | # create the gperf file |
| 42 | sed -e "/@@SYSCALLS_TABLE@@/r $(@D)/syscalls_tmp.csv" \ |
| 43 | -e '/@@SYSCALLS_TABLE@@/d' \ |
| 44 | $(location src/syscalls.perf.template) > "$(@D)/syscalls.perf" |
| 45 | ./$(location @gperf//:gperf) -m 100 --null-strings --pic -tCEG -T -S1 --output-file="$(location syscalls.perf.c)" "$(@D)/syscalls.perf" |
| 46 | """, |
| 47 | tools = [ |
| 48 | "@gperf//:gperf", |
| 49 | ], |
| 50 | ) |
| 51 | |
| 52 | template_file( |
| 53 | name = "seccomp.h", |
| 54 | src = "include/seccomp.h.in", |
| 55 | substitutions = { |
| 56 | # Irrelevant for Bazel. Just look at WORKSPACE. |
| 57 | # Make it obviously invalid so nobody is mislead. |
| 58 | "@VERSION_MAJOR@": "0", |
| 59 | "@VERSION_MINOR@": "0", |
| 60 | "@VERSION_MICRO@": "0", |
| 61 | }, |
| 62 | visibility = ["//visibility:public"], |
| 63 | ) |
| 64 | |
| 65 | cc_library( |
| 66 | name = "seccomp", |
| 67 | srcs = glob( |
| 68 | [ |
| 69 | "src/*.c", |
| 70 | "src/*.h", |
| 71 | ], |
| 72 | exclude = [ |
| 73 | "src/arch-syscall-check.c", |
| 74 | "src/arch-syscall-dump.c", |
| 75 | ], |
| 76 | ) + ["//:configure.h", ":syscalls.perf.c"], |
| 77 | hdrs = [ |
| 78 | ":seccomp.h", |
| 79 | "include/seccomp-syscalls.h", |
| 80 | ], |
| 81 | visibility = ["//visibility:public"], |
| 82 | ) |