blob: e9cf40abd870ca59a986c70b6feebbf99fdf056e [file] [log] [blame]
Serge Bazanski9e861a82020-09-16 13:46:41 +02001# 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(
18 "//build/utils:detect_root.bzl",
19 "detect_root",
20)
21
22def _linux_headers(ctx):
23 hdrs_name = ctx.attr.name + "_headers"
24 hdrs_dir = ctx.actions.declare_directory(hdrs_name)
25
26 root = detect_root(ctx.attr.src)
27 ctx.actions.run_shell(
28 inputs = ctx.files.src,
29 outputs = [hdrs_dir],
30 progress_message = "Generating Linux Kernel Headers",
31 mnemonic = "LinuxCollectHeaders",
32 arguments = [root, ctx.attr.arch, hdrs_dir.path],
33 use_default_shell_env = True,
34 command = "make -C \"$1\" headers_install ARCH=\"$2\" INSTALL_HDR_PATH=\"$(pwd)/$3\" > /dev/null && mv \"$3/include/\"* \"$3/\" && rmdir \"$3/include\"",
35 )
36 return [DefaultInfo(files=depset([hdrs_dir]))]
37
38linux_headers = rule(
39 implementation = _linux_headers,
40 attrs = {
41 "src": attr.label(mandatory = True),
42 "arch": attr.string(mandatory = True),
43 },
44)