|
1 | 1 | // Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -use std::collections::BTreeMap; |
5 | | -use std::fs::File; |
6 | 4 | use std::path::Path; |
7 | 5 |
|
8 | | -use seccompiler::common::BpfProgram; |
9 | | -use seccompiler::compiler::{Compiler, JsonFile}; |
10 | | - |
11 | 6 | const ADVANCED_BINARY_FILTER_FILE_NAME: &str = "seccomp_filter.bpf"; |
12 | 7 |
|
13 | 8 | const JSON_DIR: &str = "../../resources/seccomp"; |
@@ -44,19 +39,7 @@ fn main() { |
44 | 39 | // Also retrigger the build script on any seccompiler source code change. |
45 | 40 | println!("cargo:rerun-if-changed={}", SECCOMPILER_SRC_DIR); |
46 | 41 |
|
47 | | - let input = std::fs::read_to_string(seccomp_json_path).expect("Correct input file"); |
48 | | - let filters: JsonFile = serde_json::from_str(&input).expect("Input read"); |
49 | | - |
50 | | - let arch = target_arch.as_str().try_into().expect("Target"); |
51 | | - let compiler = Compiler::new(arch); |
52 | | - |
53 | | - // transform the IR into a Map of BPFPrograms |
54 | | - let bpf_data: BTreeMap<String, BpfProgram> = compiler |
55 | | - .compile_blob(filters.0, false) |
56 | | - .expect("Successfull compilation"); |
57 | | - |
58 | | - // serialize the BPF programs & output them to a file |
59 | 42 | let out_path = format!("{}/{}", out_dir, ADVANCED_BINARY_FILTER_FILE_NAME); |
60 | | - let output_file = File::create(out_path).expect("Create seccompiler output path"); |
61 | | - bincode::serialize_into(output_file, &bpf_data).expect("Seccompiler serialization"); |
| 43 | + seccompiler::compile_bpf(&seccomp_json_path, &target_arch, &out_path, false) |
| 44 | + .expect("Cannot compile seccomp filters"); |
62 | 45 | } |
0 commit comments