Debian Codegraph @

examples/build_example.jsonnet

raw
1 // Compiler template
2 local CCompiler = {
3 cFlags: [],
4 out: 'a.out',
5 local flags_str = std.join(' ', self.cFlags),
6 local files_str = std.join(' ', self.files),
7 cmd: '%s %s %s -o %s' % [self.compiler, flags_str, files_str, self.out],
8 };
9
10 // GCC specialization
11 local Gcc = CCompiler { compiler: 'gcc' };
12
13 // Another specialization
14 local Clang = CCompiler { compiler: 'clang' };
15
16 // Mixins - append flags
17 local Opt = { cFlags: super.cFlags + ['-O3', '-DNDEBUG'] };
18 local Dbg = { cFlags: super.cFlags + ['-g'] };
19
20 // Output:
21 {
22 targets: [
23 Gcc { files: ['a.c', 'b.c'] },
24 Clang { files: ['test.c'], out: 'test' },
25 Clang + Opt { files: ['test2.c'], out: 'test2' },
26 Gcc + Opt + Dbg { files: ['foo.c', 'bar.c'], out: 'baz' },
27 ],
28 }