blob: 4280fc28b23327dbb9d2ed64425582e1b5f65296 [file] [log] [blame]
Lorenz Brun0de18932021-03-11 00:36:48 +01001# 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
17load("@rules_cc//cc:defs.bzl", "cc_library")
18load("@dev_source_monogon//build/utils:template_file.bzl", "template_file")
19
20genrule(
21 name = "config-h",
22 outs = ["configure.h"],
23 cmd = "echo \"#define HAVE_LINUX_SECCOMP_H 1\" > \"$@\"",
24 visibility = ["//visibility:public"],
25)
26
27genrule(
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
52template_file(
53 name = "seccomp.h",
54 src = "include/seccomp.h.in",
55 substitutions = {
Lorenz Brund13c1c62022-03-30 19:58:58 +020056 # Known dependencies relying on this version information:
57 # - @com_github_seccomp_libseccomp_golang//:libseccomp-golang
58 "@VERSION_MAJOR@": "2",
59 "@VERSION_MINOR@": "5",
60 "@VERSION_MICRO@": "1",
Lorenz Brun0de18932021-03-11 00:36:48 +010061 },
62 visibility = ["//visibility:public"],
63)
64
65cc_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 ],
Serge Bazanski8ff4b7c2021-08-17 19:21:18 +020081 includes = ["."],
Lorenz Brun0de18932021-03-11 00:36:48 +010082 visibility = ["//visibility:public"],
83)