Skip to content

Commit 2189b80

Browse files
jordan-bonserJonathan Watson
authored andcommitted
feat: add bob_import_cc_binary
Generate bob_import_cc_binary modules from the Bazel import aspect and allow the imported binaries to be exposed as Bob host binaries. Change-Id: I0568c14d93e9d59d841caaf6c53cb2dd9d6b1377 Signed-off-by: Jordan Bonser <jordan.bonser@arm.com>
1 parent 52fdacf commit 2189b80

31 files changed

Lines changed: 303 additions & 20 deletions

Blueprints

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ bootstrap_go_package {
6060
"core/generated_props.go",
6161
"core/glob.go",
6262
"core/graphviz.go",
63-
"core/import_cc.go",
63+
"core/import_cc_binary.go",
64+
"core/import_cc_library.go",
6465
"core/install.go",
6566
"core/kernel_module.go",
6667
"core/late_template.go",

core/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ go_library(
3131
"generated_props.go",
3232
"glob.go",
3333
"graphviz.go",
34-
"import_cc.go",
34+
"import_cc_binary.go",
35+
"import_cc_library.go",
3536
"install.go",
3637
"kernel_module.go",
3738
"late_template.go",

core/build_structs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type generatorBackend interface {
9090
strictBinaryActions(*ModuleStrictBinary, blueprint.ModuleContext)
9191
strictLibraryActions(*ModuleStrictLibrary, blueprint.ModuleContext)
9292
importCCLibraryActions(*ModuleImportCCLibrary, blueprint.ModuleContext)
93+
importCCBinaryActions(*ModuleImportCCBinary, blueprint.ModuleContext)
9394
executableTestActions(*ModuleTest, blueprint.ModuleContext)
9495
}
9596

@@ -659,4 +660,5 @@ func RegisterModuleTypes(register func(string, FactoryWithConfig)) {
659660
register("bob_test", executableTestFactory)
660661

661662
register("bob_import_cc_library", importCCLibraryFactory)
663+
register("bob_import_cc_binary", importCCBinaryFactory)
662664
}

core/generated.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,11 @@ func hostBinOuts(hostBin *string, ctx blueprint.ModuleContext) (string, []string
183183
hostBinTarget = b.getTarget()
184184
} else if gb, ok := child.(*generateBinary); ok {
185185
outputs = file.GetOutputs(gb)
186+
} else if ib, ok := child.(*ModuleImportCCBinary); ok {
187+
outputs = file.GetOutputs(ib)
188+
hostBinTarget = ib.getTarget()
186189
} else {
187-
ctx.PropertyErrorf("host_bin", "%s is not a `bob_binary` nor `bob_generate_binary`", parent.Name())
190+
ctx.PropertyErrorf("host_bin", "%s is not a `bob_binary`, `bob_generate_binary`, nor `bob_import_cc_binary`", child.Name())
188191
return false
189192
}
190193

core/generated_common.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,11 @@ func (m *ModuleGenerateCommon) hostBinName(ctx blueprint.ModuleContext) (name st
208208
func(module blueprint.Module) {
209209
_, bin_ok := module.(*ModuleBinary)
210210
_, genbin_ok := module.(*generateBinary)
211-
if bin_ok || genbin_ok {
211+
_, importbin_ok := module.(*ModuleImportCCBinary)
212+
if bin_ok || genbin_ok || importbin_ok {
212213
name = module.Name()
213214
} else {
214-
ctx.PropertyErrorf("host_bin", "%s is not a `bob_binary` nor `bob_generate_binary`", module.Name())
215+
ctx.PropertyErrorf("host_bin", "%s is not a `bob_binary`, `bob_generate_binary`, nor `bob_import_cc_binary`", module.Name())
215216
}
216217
})
217218

core/import_cc_binary.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package core
2+
3+
import (
4+
"path/filepath"
5+
6+
"github.com/ARM-software/bob-build/core/file"
7+
"github.com/ARM-software/bob-build/core/module"
8+
"github.com/ARM-software/bob-build/core/toolchain"
9+
"github.com/google/blueprint"
10+
)
11+
12+
type ImportCCBinaryProps struct {
13+
Src string
14+
Target toolchain.TgtType
15+
}
16+
17+
type ModuleImportCCBinary struct {
18+
module.ModuleBase
19+
Properties struct {
20+
SplittableProps
21+
ImportCCBinaryProps
22+
}
23+
}
24+
25+
var _ splittable = (*ModuleImportCCBinary)(nil)
26+
var _ file.Provider = (*ModuleImportCCBinary)(nil)
27+
28+
func importCCBinaryFactory(config *BobConfig) (blueprint.Module, []interface{}) {
29+
module := &ModuleImportCCBinary{}
30+
31+
return module, []interface{}{&module.Properties, &module.SimpleName.Properties}
32+
}
33+
34+
func (g *linuxGenerator) importCCBinaryActions(m *ModuleImportCCBinary, ctx blueprint.ModuleContext) {
35+
addPhony(m, ctx, file.GetOutputs(m), false)
36+
}
37+
38+
func (g *androidNinjaGenerator) importCCBinaryActions(m *ModuleImportCCBinary, ctx blueprint.ModuleContext) {
39+
40+
}
41+
42+
func (g *androidBpGenerator) importCCBinaryActions(m *ModuleImportCCBinary, ctx blueprint.ModuleContext) {
43+
44+
}
45+
46+
func (m *ModuleImportCCBinary) GenerateBuildActions(ctx blueprint.ModuleContext) {
47+
getGenerator(ctx).importCCBinaryActions(m, ctx)
48+
}
49+
50+
func (m *ModuleImportCCBinary) outputFileName() string {
51+
return m.Name()
52+
}
53+
54+
func (m *ModuleImportCCBinary) shortName() string {
55+
return m.Name()
56+
}
57+
58+
func (m *ModuleImportCCBinary) processPaths(ctx blueprint.BaseModuleContext) {
59+
m.Properties.Src = filepath.Join(projectModuleDir(ctx), m.Properties.Src)
60+
}
61+
62+
func (m *ModuleImportCCBinary) OutFiles() file.Paths {
63+
return file.Paths{
64+
file.NewPath(
65+
m.Properties.Src,
66+
file.FileNoNameSpace,
67+
file.TypeSrc|file.TypeInstallable,
68+
),
69+
}
70+
}
71+
72+
func (m *ModuleImportCCBinary) OutFileTargets() (tgts []string) {
73+
return
74+
}
75+
76+
// Support Splittable properties
77+
func (m *ModuleImportCCBinary) supportedVariants() []toolchain.TgtType {
78+
return []toolchain.TgtType{m.Properties.Target}
79+
}
80+
81+
func (m *ModuleImportCCBinary) setVariant(variant toolchain.TgtType) {
82+
// No need to actually track this, as a single target is always supported
83+
}
84+
85+
func (m *ModuleImportCCBinary) disable() {
86+
// This should never actually be called, as we will always support one target
87+
panic("disable() called on ModuleImportCCBinary")
88+
}
89+
90+
func (m *ModuleImportCCBinary) getSplittableProps() *SplittableProps {
91+
return &m.Properties.SplittableProps
92+
}
93+
94+
func (m *ModuleImportCCBinary) getTarget() toolchain.TgtType {
95+
return m.Properties.Target
96+
}
97+
98+
// End Support Splittable properties
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Module: bob_import_cc_binary
2+
3+
> Warning, this target is experimental and the attributes/interface are likely to keep changing.
4+
5+
```bp
6+
bob_import_cc_binary {
7+
name, src, target
8+
}
9+
```
10+
11+
This target makes an externally built executable available in the Bob build graph. It does not expose headers, defines, or linker flags; it only provides the binary artifact to other rules.
12+
13+
## Properties
14+
15+
| | |
16+
| ---------------------------------------------- | ------------------------------------------------------------------------------------- |
17+
| [`name`](properties/common_properties.md#name) | String; required |
18+
| `src` | Path of the built executable. |
19+
| `target` | One of either `host` or `target`. Whether the executable is built for host or target. |

gendiffer/tests/cc_import/binary/WORKSPACE

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build.bp

0 commit comments

Comments
 (0)