A method and system for minimizing the assembly of application-driven components for a single kernel
By using cross-language static analysis and rule-based minimization, the configuration of mono-kernel system components is automatically derived, solving the problem of reliance on human experience in existing technologies and achieving efficient and traceable component minimization assembly that adapts to different platforms and languages.
Patent Information
- Application Number
- CN202611618645.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-20
- Publication Date
- 2026-11-17
AI Technical Summary
Existing technologies cannot automatically deduce the component configuration of a single-kernel system from the source code of the target application, resulting in configuration results that rely on human experience, contain errors and redundancies, are difficult to adapt to different platforms and languages, and lack cross-language static analysis capabilities.
API call information is identified through cross-language differential static analysis. Combined with a unified conditional expression model and an external rule base, the minimum component set is automatically derived, and a minimum image is generated through rule-based and validation-based minimization.
It enables automated configuration based on the target application's source code, reducing human experience errors, is applicable to different platforms and languages, reduces image size and attack surface, and provides traceable assembly results.
Smart Images

Figure CN123114486A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method and system for minimizing application-driven components for a single kernel, specifically to a method and system for deriving the minimum set of components required by the operating system based on the source code of the target application and completing the image construction, belonging to the field of operating system construction and single-kernel image generation technology. Background Technology
[0002] A unikernel is a technology that compiles a target application and its dependent system components into a single executable image on demand. Compared to traditional general-purpose operating systems, a unikernel image only needs to contain the kernel components necessary for the application to run, thus offering advantages such as small size, fast startup, narrow attack surface, and low resource overhead. It has wide application value in cloud computing, edge computing, embedded systems, and security-critical fields.
[0003] Existing monolithic kernel systems (including but not limited to ArceOS, Unikraft, MirageOS, IncludeOS, etc.) typically possess some component-based building capabilities, allowing for the selective enabling or disabling of system submodules such as the network stack, file system, multitasking scheduling, memory management, and device drivers through declarative configuration. However, these mechanisms mostly address the question of "how to build given a configuration," not "how the configuration itself is obtained." In practical engineering, the selection of top-level components often still relies on the developer's experience.
[0004] Currently, common solutions mainly include the following categories:
[0005] The first type is manual configuration. Developers manually specify the system features or components to be enabled based on application requirements and framework experience. For example, in ArceOS, developers need to explicitly list the required system features in the build command using FEATURES=alloc, multitask, etc.; in Unikraft, developers need to select the required library configurations item by item through the menuconfig interface (CONFIG_LIBXXX=y). This approach is simple to implement, but has obvious limitations: the configuration results are highly dependent on human experience. Different developers may provide different configuration schemes for the same application; there are transitive dependencies between components (such as the network subsystem depending on memory allocation and page table management), and it is difficult to configure completely at once using only the surface interface; missing dependencies will lead to compilation failures or runtime anomalies. When the target platform, processor architecture, or bus type changes, the driver selection and bus binding in the original configuration are difficult to reuse directly; in order to reduce development and debugging costs, developers usually tend to introduce redundant components, resulting in the final image size being larger than the actual application requirements; there is a lack of a clear mapping relationship between the final configuration and the actual application requirements, which is not conducive to traceability, auditing, and reproduction.
[0006] The second category is linker-based dead code elimination. Some compiler toolchains provide link-time optimization (LTO) and dead code elimination capabilities, which can remove uncalled functions and data segments during the linking stage. However, this approach has the following shortcomings in a single-kernel scenario: dead code elimination operates at the level of already compiled target code and cannot affect component selection or conditional compilation decisions during the compilation stage, i.e., it cannot reduce the number of components involved in compilation from the source; for code paths controlled by conditional compilation (such as Rust's #[cfg(...)] or C's #ifdef), the linker cannot determine its relevance to the target platform. There is a lack of a unified source code analysis and configuration derivation mechanism for Rust and C projects, making it difficult to complete cross-language feature extraction and comprehensive configuration decisions within the same processing framework.
[0007] The third category is dependency transitivity based on the build system. Some build systems (such as Cargo's feature transitivity mechanism and Kconfig's select / depends on mechanism) can automatically transitive some dependencies. However, this mechanism is based on the premise that the developers have correctly declared the required features at the top level. In essence, it is still an "execution mechanism given a configuration" rather than a decision-making mechanism that "automatically obtains the configuration based on the target application".
[0008] In summary, existing technologies still have the following shortcomings: a mechanism for automatically inferring system capability requirements based on the target application's source code has not yet been formed; differentiated static analysis capabilities for cross-language (Rust / C) projects are lacking; it is difficult to combine conditional compilation context with target platform for relevance filtering; the analysis engine has not been effectively decoupled from specific single-kernel framework rules; existing solutions have not yet formed a minimal processing mechanism that takes into account both rule pruning and actual build verification; at the same time, a traceability mechanism from source code evidence to the final component set is also lacking. Summary of the Invention
[0009] To address the shortcomings of existing technologies, this invention provides a method and system for minimizing the assembly of application-driven components for a single kernel. This method starts with the source code of the target application, first identifies the interfaces and capability requirements actually used by the application, and then, in combination with target platform information, external rule bases, and dependencies, automatically solves for the minimum set of components for single-kernel construction and generates corresponding build artifacts and assembly reports.
[0010] This invention uses source code evidence to replace human experience to achieve automated assembly decision-making, avoids cross-platform misassembly through conditional filtering, achieves multi-framework adaptation through engine and rule separation, and significantly reduces image size and attack surface through double-layer minimization. The generated assembly result has complete evidence traceability.
[0011] The present invention adopts the following technical solution:
[0012] A method for minimizing the assembly of application-driven components for a single kernel includes the following steps:
[0013] S1, obtain the target application path, target platform identifier, architecture coverage information, bus information, verification mode, probe port, report output directory, and rule directory path;
[0014] S2 identifies the language type of the target application and selects the corresponding analysis strategy based on the language type;
[0015] S3 performs cross-language differential static analysis on the target application source code, identifies API call information, records the corresponding conditional compilation constraints, and forms application analysis results.
[0016] S4, based on the unified conditional expression model and combined with target architecture information, performs platform-related filtering on API call information, thereby filtering out irrelevant evidence;
[0017] S5 maps the filtered application analysis results to the initial feature set based on the external rule base, and generates a candidate feature set through dependency closure solving and platform-driven completion.
[0018] S6, perform first-level rule-based minimization on the candidate feature set, and delete redundant features that lack source code information support and are not dependent on or platform-essential;
[0019] S7, perform the second-level verification-based trial deletion minimization on the feature set after the first-level regular minimization, temporarily delete candidate features one by one and call the construction process to verify, so as to obtain the minimum feature set that has further converged;
[0020] S8 transforms the minimum feature set into a configuration form acceptable to the target build system, injects it into a single-kernel build chain, and generates a minimal image.
[0021] S9 outputs the assembly results and assembly report; the assembly report includes API call information, conditional evidence set, feature set of each stage, trimming record, module set and construction results.
[0022] In the above steps, S2 to S4 are used to extract capability evidence related to the target platform from the target application source code; S5 to S7 are used to converge the capability evidence into a minimal set of assemblable features; and S8 to S9 are mainly used to integrate the assembly results into the build process and output auditable artifacts. This layered processing approach decouples analysis, decision-making, building, and reporting, which is beneficial for replacing target framework rules and for reuse across different automated processes.
[0023] Throughout the process, the target platform identifier, architecture coverage information, bus information, and verification mode obtained in step S1 are continuously transmitted as a unified context. Specifically, the target platform identifier is used for platform relevance filtering in step S4, platform driver completion in step S5, and build configuration generation in step S8; the verification mode is used for trial deletion verification in step S7 and result output range control in step S9.
[0024] The key to this invention lies in establishing an automated derivation chain from "application source code evidence" to "a single kernel component set." This chain includes three key mechanisms: first, a differentiated static analysis mechanism for Rust / C applications, used to extract API call evidence and its conditional compilation context; second, a unified conditional expression model, used to unify conditional compilation constraints in different languages and evaluate their relevance with the target platform, thereby filtering out irrelevant evidence; and third, a two-layer minimization processing mechanism combining rule-based pruning and verification-based trial deletion, used to further compress the component set while ensuring the correctness of the build.
[0025] Preferably, in step S2, the system determines the language type based on the project description file in the target application path to determine the source code processing link of the subsequent application, thus avoiding the omission of evidence or misjudgment caused by using the same analysis strategy for Rust and C applications.
[0026] If the Cargo.toml file exists in the target application directory, it is identified as a Rust application; otherwise, it is identified as a C application. In addition to the type identifier, the language recognition step can also output project description information related to subsequent analysis, such as the location of the package description file, the location of the source code root directory, and the location of optional build auxiliary files, in order to reduce subsequent repeated scanning.
[0027] For Rust applications, perform Rust differential static analysis; for C applications, perform C differential static analysis.
[0028] If both Rust and C source code files exist in the target directory, the main analysis chain can be determined based on the dominance of the top-level project description file, and the extended scanning capability for auxiliary language files can be retained in step S3. For example, if Cargo.toml exists in the directory and contains a small amount of .c auxiliary source code, it can be processed as a Rust application first, while supplementing the joint analysis of C auxiliary modules in the extended implementation.
[0029] In addition to the methods mentioned above, file extension statistics, build script types, or project metadata can also be used to determine the application language type. For example, the Makefile, compile_commands.json, or custom project description file can be used to help determine the application language type. For projects that cannot be clearly identified, a conservative strategy can be adopted to perform file scanning first and output the language identification results to be confirmed, so that subsequent processes can select the default analysis branch.
[0030] Preferably, in step S3, for Rust applications, firstly, .rs source files under the target application path are recursively collected, and runtime-related feature information declared in Cargo.toml is read. Then, Rust differential static analysis is performed on the collected source files. Rust differential static analysis includes High-level Intermediate Representation (HIR), Abstract Syntax Tree (AST), and fallback matching analysis. Priority is given to using HIR, which has error recovery capabilities, to extract application-side evidence. For source files that HIR fails to process, AST is used to supplement the analysis. For complex source files that still cannot be stably parsed, fallback matching analysis based on string patterns is further employed to improve robustness in handling complex projects and incomplete source code.
[0031] During the extraction of conditional compilation information, a conditional compilation stack is maintained synchronously to record the conditional compilation context. Specifically, when the iterator enters a syntax node with the conditional compilation attribute #[cfg(...)], the conditional expression declared in that attribute is pushed onto the conditional stack; when the iterator leaves the syntax node, the corresponding conditional expression is popped off. The conditional compilation attribute #[cfg(...)] is a Rust attribute used to describe the conditions under which code takes effect, and can be used to limit specific code to participate in compilation only when conditions such as target architecture, target operating system, target features, or compilation features are met. This allows API calls, type paths, macro calls, and use declarations located under different conditional branches to be associated with their actual effective compilation context. Finally, the file path and line number corresponding to each piece of evidence are recorded to form source code location information, providing a basis for subsequent platform-related filtering and feature deduction.
[0032] Based on the above analysis, application-side evidence related to capability derivation is extracted. This application-side evidence includes API call information such as use path references, external library (crate) references, function call expressions, method call expressions, type paths, and macro calls.
[0033] For C applications, the processing procedure is as follows:
[0034] First, .c and .h source files under the target application path are recursively collected, with optional reading of explicit capability input files. Then, C differential static analysis is performed on the collected source files. This analysis includes Clang Abstract Syntax Tree (AST) analysis based on the Clang compiler frontend (Clang, C Language Family Frontend) and regular expression fallback matching analysis, prioritizing Clang AST analysis. If compile_commands.json exists, corresponding compilation parameters are further extracted to improve the accuracy of macro definition processing, header file path parsing, and semantic recognition. Upon successful AST analysis, function call entities and their corresponding file locations and line numbers are extracted. For source files that cannot be stably processed by Clang AST analysis, C language application programming interface (API) patterns are loaded from an external rule base. The source code is matched line by line using regular expressions with word boundary constraints to continue extracting application-side evidence. During the regular expression backtracking matching analysis, a preprocessing condition stack is maintained simultaneously to record the preprocessing condition context. Specifically, when encountering preprocessing directives such as #ifdef, #ifndef, #if, #elif, #else, and #endif, condition push, condition substitution, condition negation, or condition pop operations are performed respectively. For ordinary lines of code, API pattern recognition is performed under the current preprocessing condition context, and the corresponding capability name, hit position, and condition snapshot are recorded. For evidence obtained through abstract syntax tree analysis or regular expression backtracking matching, the preprocessing conditions that took effect before its current position can be further traced back, and the architecture-related macro expressions are uniformly converted into the condition expression form used for subsequent evaluation.
[0035] In addition, when the system detects network or file descriptor-related capabilities such as net, select, and epoll, it can automatically add file descriptor capabilities (fd) to reduce the risk of capability omissions due to indirect dependencies in C / POSIX scenarios.
[0036] Through differentiated static analysis, a unified application analysis result is obtained, which includes a capability evidence set, source code location information, conditional compilation context, and optional runtime feature information. The capability evidence set refers to the set of evidence extracted from the target application source code and uniformly organized, which can be used for capability inference, rather than simply referring to the abstract capability name itself. For Rust applications, the capability evidence set mainly includes use path references, external library (crate) references, function call expressions, method call expressions, type paths, macro calls, and runtime-related features declared in Cargo.toml. For C applications, the capability evidence set mainly includes function call patterns identified through Clang abstract syntax tree analysis or regular expression backtracking, capability information declared in explicit capability input files, and capability mapping information corresponding to interface pattern matching results. All of the above evidence can be further associated with their corresponding file paths, line numbers, and conditional contexts, thus forming a traceable unified analysis result. Although Rust and C have different source-level structures, after unified organization, both can enter the same subsequent assembly decision process.
[0037] In this invention, the abstract syntax tree analysis based on the Clang compiler frontend is a source code semantic analysis method based on the Clang compiler frontend, which is itself an existing compiler frontend analysis technology. This invention introduces this analysis method into the C application capability evidence extraction process and combines it with regular expression fallback, condition tracking, and subsequent assembly decision.
[0038] Preferably, in step S4, the unified conditional expression model is used to convert the conditional compilation context in the Rust application and the preprocessing conditional context in the C application into a conditional expression object that can be processed jointly. Specifically:
[0039] For Rust applications, the conditional expressions #[cfg(target_arch = "...")], #[cfg(target_os ="...")], #[cfg(target_feature = "...")], #[cfg(feature = "...")], and not(...), any(...), all(...) are parsed and normalized into target architecture condition TargetArch, target operating system condition TargetOs, target processor feature condition TargetFeature, compilation feature condition Feature, logical NOT, logical OR Any, and logical AND All unified condition types.
[0040] For C applications, preprocessor conditions such as #ifdef, #ifndef, #if, #elif, #else, and #endif are mapped to a unified condition type identical to those in Rust applications after macro identification, logical decomposition, and condition normalization. For example, #ifdef __x86_64__ can be converted to TargetArch("x86_64"), #ifndef __aarch64__ can be converted to Not(TargetArch("aarch64")), and #if defined(A) && defined(B) can be converted to the logical AND condition All(...). Conditional expressions that cannot be further normalized are uniformly denoted as Other. In this way, conditional compilation constraints in different languages can be transformed into the same evaluation object, thus enabling unified processing in the same filtering stage.
[0041] The core of step S4 lies in further limiting "information that has appeared in the source code" to "information that is truly effective for the current target platform," in order to avoid an overly broad scope of capability deduction due to the simultaneous existence of cross-platform code, conditional compilation branches, or placeholder implementations. Evidence without conditional constraints can be directly regarded as being related to the current target platform;
[0042] For evidence with conditional constraints, each item is evaluated in conjunction with the current target context. Specifically, for the target architecture condition `TargetArch`, it is determined whether it matches the current target architecture; for the target operating system condition `TargetOs`, it is determined whether it matches the current target operating system; for the target processor feature condition `TargetFeature`, it is determined whether the current target possesses the corresponding processor feature; for the compilation feature condition `Feature`, it is determined whether the corresponding compilation feature is enabled in the current build context; for logical NOT conditions, its internal sub-conditions are evaluated first, and then the result is inverted; for logical OR `Any`, it is determined to be true as long as any sub-condition is true; for logical AND `All`, it is determined to be true only if all sub-conditions are true. For compilation feature conditions or other conditions whose truth values cannot be determined temporarily, a conservative retention strategy can be adopted, that is, relevant evidence is not deleted for the time being to reduce the risk of missing key capabilities. Through the above evaluation process, irrelevant evidence that only exists in other architectures, other operating systems, or other conditional branches can be excluded, and only information that is truly relevant to the current target platform can be retained, thereby avoiding incorrect capability derivation and reducing the risk of misassembly.
[0043] For example, when the target platform is x86_64, network interface calls that only appear under the condition #[cfg(target_arch = "aarch64")] will be filtered out, preventing incorrect deduction of network function requirements. Similarly, if a call in the C source code is only located under the #ifdef __aarch64__ branch, that call will not participate in solving for the capabilities of the x86_64 target platform.
[0044] Preferably, this invention employs a structure that separates the analysis engine from the rule base. The analysis engine is responsible for extracting and organizing application-side evidence. Application-side evidence refers to the set of source code evidence extracted and uniformly organized from the target application's source code, including interface call information related to capability derivation, source code location information, conditional context, and optional runtime feature information. Specifically, for Rust applications, application-side evidence can be obtained through the analysis of .rs source files and Cargo.toml; for C applications, application-side evidence can be obtained through the analysis of .c and .h source files, explicit capability input files, and related compilation information. Specific framework-related knowledge is maintained by an external rule base, avoiding the solidification of component rules for a single-kernel framework within the engine. At runtime, different rule sets can be switched via rule directory parameters, allowing the same analysis engine to adapt to different single-kernel systems.
[0045] In step S5, the external rule base refers to a collection of rule files that are maintained independently of the analysis engine and loaded at runtime through the rule directory path. The external rule base includes API-to-feature mapping rules, feature dependency closure rules, platform-to-bus and driver mapping rules, build configuration rules, and feature-to-module mapping rules. The mapping rules can be used for candidate feature solving, as well as for subsequent build adaptation and report output.
[0046] In step S5, firstly, based on the API-to-feature mapping rules in the external rule base, the API calls, function symbols, project description file feature declarations, or explicit feature inputs retained after conditional correlation filtering in the application analysis results are converted into a direct feature set, which is then used as the initial feature set. Direct features refer to functional features obtained directly from application-side evidence and API-to-feature mapping rules, excluding underlying dependency features derived from dependency closure rules, as well as platform features or driver features added by platform-to-bus and driver mapping rules. Subsequently, transitive expansion is performed based on the closure dependency relationships in the external rule base, adding the underlying features necessary for the direct features to the candidate feature set. After the dependency closure is solved, platform-related completion is further performed in conjunction with the target platform information. If the analysis results explicitly give the bus type, the corresponding bus feature is added to the candidate feature set. If the rule base defines driver features for the current platform and current capability combination, the driver features are added to the candidate feature set.
[0047] Therefore, the candidate feature set not only covers the functional requirements reflected by direct application calls, but also the underlying assembly items required when the function is actually implemented on the target platform.
[0048] Preferably, in step S6, the candidate feature set obtained in step S5 is subjected to first-level rule-based minimization. That is, without invoking real-world construction verification, the candidate set is pruned according to source code evidence, direct capability requirements, dependencies, and platform necessities to remove obviously redundant features and reduce the search space for subsequent verification-based trial deletion.
[0049] The process of minimizing the first-level regularity in step S6 is as follows:
[0050] ① First, extract the set of evidence capabilities with source code location information from the application analysis results, and combine it with the set of candidate features generated in step S5 to establish the decision boundary for retention: all features that are supported by direct source code evidence, or features that belong to direct capability mapping results, closure dependency results, or platform-driven completion results are considered as features that should not be deleted in the current stage.
[0051] ② Features used to describe platform bus type or device driver type, such as bus features and driver class features, can be directly retained. The reason is that although these features may not correspond to direct call information in the application source code, they are usually derived from platform rules and are necessary configuration items required for successful construction of the target platform and device access.
[0052] Features that do not meet conditions ① or ② are marked as redundant features and removed from the candidate feature set. The reason and name of the removal are recorded to create a traceable pruning record in the report. The result obtained after this step can be used as input for the second-level verification-based trial-and-error minimization, or it can be directly output as the final assembly result when verification mode is off.
[0053] Preferably, in step S7, the implementation process of the verification-based trial deletion minimization is as follows:
[0054] First, construct a set of essential features that cannot be attempted to be deleted. This set includes basic dependency features obtained from dependency closure solving, driver features obtained from platform driver completion, and structural features with bus or driver prefixes. These features typically serve as underlying dependencies, platform adaptations, or device access mechanisms. If they are attempted to be deleted rashly, it may lead to a large number of meaningless verification failures. Therefore, they are directly excluded from the scope of attempted deletion in this step.
[0055] After determining the necessary feature set, the remaining features constitute the candidate deletion set, i.e., non-essential features. Subsequently, deletion is performed item by item in the candidate deletion set in a predetermined order. For each feature to be deleted, a temporary experimental feature set after deleting the feature is generated and injected into the target construction process for verification. If the verification is successful, it means that the feature to be deleted is not necessary to maintain the current construction result, and it is removed from the current feature set. If the verification fails, the feature to be deleted is restored and the next feature to be deleted is processed until all candidate deletion sets have been deleted, and finally the minimum feature set is formed.
[0056] Preferably, the verification process employs a single verification mode, which can be one of the following: compilation verification, test verification, virtual machine startup verification, or service port detection verification. Compilation verification is based on the successful completion of the build process. Test verification, in addition to successful build, further requires successful execution of the test commands. Virtual machine startup verification requires valid startup output within a limited time after the image starts. Service port detection verification requires a successful connection to the target port after the image starts. Finally, step S7 outputs the minimized result obtained under the constraints of the selected verification mode, rather than a purely rule-based derivation result detached from actual build conditions.
[0057] Preferably, in step S8, firstly, the minimum feature set is filtered according to the output filtering rules in the external rule base, removing features that do not need to be directly output, and the filtered features are written to the feature list file features.txt in comma-separated form for the build system to read directly; secondly, according to the predefined environment variable mapping relationship in the external rule base, the minimum feature set is further converted into build variables or configuration fragments, generating the environment variable file env.mk for the build system to load and use in subsequent build processes, wherein each variable can be protected by a protection mechanism to avoid overwriting the configuration explicitly specified by the user; thus, the aforementioned analysis and decision results are transformed from an internal derivation state into input artifacts that the build system can directly use, realizing a closed loop from automatic assembly results to actual image build; when report output is not enabled, a summary file summary.txt is further generated, which includes the target application, language type, target platform, and the final minimum feature set, for the build script or manual viewing of the analysis results.
[0058] The generated minimized image includes the following forms: ①Features.txt file: Features are written to the file in comma-separated form for the build system to read and override the FEATURES variable; certain features can be excluded according to the output filtering mode defined in the rules, such as driving features that can be automatically derived from other features in the target framework; ② Environment variable file env.mk; Based on the environment variable mapping in the external rule base, features are converted into build system environment variables. Each environment variable is protected by the $(origin) protection mechanism and only takes effect when the user does not explicitly set it through the command line, so as to avoid overwriting the user's manual configuration. ③ Summary file summary.txt; when report output is not enabled, a summary file is generated. The summary file includes the target application, language type, target platform and final feature set, for script building or manual review of analysis results.
[0059] In the extended form, for frameworks using the Kconfig configuration system, the feature can be further mapped to CONFIG_ Variables or other configuration fragments. Further, step S8 may also be performed by the build adaptation layer, which may generate build commands, working directories, and additional parameters according to the conventions of the target framework, and inject the artifacts as intermediate inputs into make, cargo, scripted builders, or virtual machine startup scripts.
[0060] Preferably, in step S9, the output of the assembly report includes a structured report (JSON) and a human-readable report (Markdown). The structured report (JSON) corresponds to a structured report file, which records structured content such as application path, language type, target platform, capability set, API call evidence, condition information, feature set of each stage, module set, and build result. The human-readable report (Markdown) corresponds to a human-readable report file, which is used to display the assembly process, evidence source, trimming records, and final output result in a readable manner.
[0061] The assembly result includes at least a final feature set file and a summary file. When report output or build output is enabled, a structured report and a human-readable report can also be generated. Through the above output information, developers can clearly see the source, dependencies, trimming process, and corresponding build status of each final feature, thus forming a complete audit chain from the source code location to the assembly result.
[0062] A minimal assembly system for application-driven components oriented to a single kernel, characterized in that it includes:
[0063] The input acquisition module is used to acquire the target application path, target platform identifier, architecture coverage information, bus information, verification mode, probe port, report output directory, and rule directory path;
[0064] The language recognition module is used to determine the language type of the target application based on the project description file;
[0065] The Rust source code analysis module is used to extract API call information based on high-level intermediate representation parsing and abstract syntax tree parsing, and to fall back to string matching when necessary, while maintaining the conditional compilation stack;
[0066] The C source code analysis module is used for abstract syntax tree analysis and regular expression backtracking matching based on the Clang compilation front-end to extract API call information, and synchronously maintains the preprocessing condition stack;
[0067] The conditional filtering module is used to perform target architecture relevance filtering on API call information based on a unified conditional expression model;
[0068] The analysis results module is used to generate application analysis results that include a set of functional requirements, source mapping, and operational characteristics.
[0069] The rule loading module is used to load API mapping rules, feature dependency closure rules, platform-to-bus and driver mapping rules, build rules, and feature-to-module rules from external rule bases;
[0070] The dependency closure solving module is used to perform transitive dependency unrolling based on feature-based dependency closure rules;
[0071] The platform driver completion module is used to supplement bus features and driver features based on the platform-to-bus and driver mapping rules and the current set of functional requirements.
[0072] The rule-based minimization module is used to remove redundant features that lack supporting evidence based on source code information;
[0073] The verification-based minimization module is used to attempt deletions item by item and determine whether a feature can be deleted by constructing a verification module.
[0074] Build an adaptation module to convert the final feature set into a configuration format acceptable to the target build system and inject it into the build chain;
[0075] The report generation module is used to output structured reports in JSON format and human-readable reports in Markdown format.
[0076] The modules described above can be deployed on the same electronic device or, functionally, across multiple collaborative nodes. For example, the source code analysis module and the conditional filtering module can be deployed on the development host, while the verification-based minimization module and the build adaptation module can be deployed on a continuous integration environment or a remote build node. Modules can exchange data via files, command-line arguments, memory objects, or structured messages.
[0077] The assembly decision engine is comprised of a language recognition module, a source code analysis module, a conditional filtering module, a rule loading module, a candidate feature solving module, and a minimization module, while the adaptation module and the report generation module constitute the delivery output layer. This modular division allows for migration and adaptation to different monolithic systems without altering the core logic of the analysis engine, simply by replacing the rule files and building the adaptation layer.
[0078] For any details not covered in this invention, please refer to the prior art.
[0079] The beneficial effects of this invention are as follows: This invention can automatically deduce system capability requirements based on the target application's source code, replacing manual experience with static source code analysis evidence to reduce configuration inconsistencies caused by differences in individual experience. It provides cross-language analysis capabilities, handling both Rust and C applications simultaneously, suitable for single-language and mixed-language projects. By combining a unified conditional expression model and target platform evaluation results, it filters source code information irrelevant to the current target platform, thereby reducing the risk of misassembly caused by multi-platform conditional compilation branches. It can adapt to different single-kernel systems by separating the analysis engine from the rule base, eliminating the need to modify the core code of the analysis engine when adding support for new target frameworks. It can further converge the component set through a combination of rule-based minimization and verification-based trial-and-error minimization, reducing image size and attack surface while ensuring correct build performance. Furthermore, it retains the correspondence between source code line numbers and the final module set, facilitating auditing, reproduction, and regression analysis, and integrates into the existing build process as an automatic pre-build decision layer without altering the target framework's original module system and build infrastructure. Attached Figure Description
[0080] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments of this application and their descriptions are used to explain this application and do not constitute an undue limitation of this application.
[0081] Figure 1 This is a flowchart illustrating the overall process of a method for minimizing the assembly of application-driven components for a single kernel, as described in this invention.
[0082] Figure 2 This is a block diagram of the overall functional modules of the system of the present invention;
[0083] Figure 3 This is a schematic diagram of the Rust application analysis process in this invention;
[0084] Figure 4 This is a schematic diagram of the C application analysis and preprocessing condition tracking process in this invention;
[0085] Figure 5 This is a schematic diagram of the unified condition expression model and target relevance filtering of the present invention;
[0086] Figure 6 This is a schematic diagram of the architecture for decoupling the analysis engine from the external rule directory of this invention;
[0087] Figure 7 This is a schematic diagram of the candidate feature solving and two-layer minimization process of the present invention;
[0088] Figure 8 This is a schematic diagram illustrating the relationship between the assembly result output and evidence traceability of this invention. Detailed Implementation
[0089] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this invention will be clearly and completely described below with reference to the accompanying drawings. However, this is not the only description; all aspects not described in detail herein are based on conventional techniques in the art.
[0090] Example 1
[0091] A minimal assembly method for application-driven components oriented to a single kernel, such as Figure 1 It includes the following steps:
[0092] S1, obtain the target application path, target platform identifier, architecture coverage information, bus information, verification mode, probe port, report output directory, and rule directory path;
[0093] S2 identifies the language type of the target application and selects the corresponding analysis strategy based on the language type;
[0094] S3 performs cross-language differential static analysis on the target application source code, identifies API call information, records the corresponding conditional compilation constraints, and forms application analysis results.
[0095] S4, based on the unified conditional expression model and combined with target architecture information, performs platform-related filtering on API call information, thereby filtering out irrelevant evidence;
[0096] S5 maps the filtered application analysis results to the initial feature set based on the external rule base, and generates a candidate feature set through dependency closure solving and platform-driven completion.
[0097] S6, perform first-level rule-based minimization on the candidate feature set, and delete redundant features that lack source code information support and are not dependent on or platform-essential;
[0098] S7, perform the second-level verification-based trial deletion minimization on the feature set after the first-level regular minimization, temporarily delete candidate features one by one and call the construction process to verify, so as to obtain the minimum feature set that has further converged;
[0099] S8 transforms the minimum feature set into a configuration form acceptable to the target build system, injects it into a single-kernel build chain, and generates a minimal image.
[0100] S9 outputs the assembly results and assembly report; the assembly report includes API call information, conditional evidence set, feature set of each stage, trimming record, module set and construction results.
[0101] In the above steps, S2 to S4 are used to extract capability evidence related to the target platform from the target application source code; S5 to S7 are used to converge the capability evidence into a minimal set of assemblable features; and S8 to S9 are mainly used to integrate the assembly results into the build process and output auditable artifacts. This layered processing approach decouples analysis, decision-making, building, and reporting, which is beneficial for replacing target framework rules and for reuse across different automated processes.
[0102] Throughout the process, the target platform identifier, architecture coverage information, bus information, and verification mode obtained in step S1 are continuously transmitted as a unified context. Specifically, the target platform identifier is used for platform relevance filtering in step S4, platform driver completion in step S5, and build configuration generation in step S8; the verification mode is used for trial deletion verification in step S7 and result output range control in step S9.
[0103] The key to this invention lies in establishing an automated derivation chain from "application source code evidence" to "a single kernel component set." This chain includes three key mechanisms: first, a differentiated static analysis mechanism for Rust / C applications, used to extract API call evidence and its conditional compilation context; second, a unified conditional expression model, used to unify conditional compilation constraints in different languages and evaluate their relevance with the target platform, thereby filtering out irrelevant evidence; and third, a two-layer minimization processing mechanism combining rule-based pruning and verification-based trial deletion, used to further compress the component set while ensuring the correctness of the build.
[0104] Example 2
[0105] A method for minimizing the assembly of application-driven components for a single kernel, as described in Example 1, differs in that, in step S2, the system determines the language type based on the project description file in the target application path to determine the source code processing link of the subsequent application, thus avoiding the omission of evidence or misjudgment caused by using the same analysis strategy for Rust and C applications.
[0106] If the Cargo.toml file exists in the target application directory, it is identified as a Rust application; otherwise, it is identified as a C application. In addition to the type identifier, the language recognition step can also output project description information related to subsequent analysis, such as the location of the package description file, the location of the source code root directory, and the location of optional build auxiliary files, in order to reduce subsequent repeated scanning.
[0107] For Rust applications, perform Rust differential static analysis; for C applications, perform C differential static analysis.
[0108] If both Rust and C source code files exist in the target directory, the main analysis chain can be determined based on the dominance of the top-level project description file, and the extended scanning capability for auxiliary language files can be retained in step S3. For example, if Cargo.toml exists in the directory and contains a small amount of .c auxiliary source code, it can be processed as a Rust application first, while supplementing the joint analysis of C auxiliary modules in the extended implementation.
[0109] In addition to the methods mentioned above, file extension statistics, build script types, or project metadata can also be used to determine the application language type. For example, the Makefile, compile_commands.json, or custom project description file can be used to help determine the application language type. For projects that cannot be clearly identified, a conservative strategy can be adopted to perform file scanning first and output the language identification results to be confirmed, so that subsequent processes can select the default analysis branch.
[0110] Example 3
[0111] A method for minimizing the assembly of application-driven components for a single kernel, as described in Example 2, differs in that, in step S3, as... Figure 3 As shown, for Rust applications, firstly, .rs source files under the target application path are recursively collected, and runtime-related feature information declared in Cargo.toml is read. Then, Rust differential static analysis is performed on the collected source files. Rust differential static analysis includes High-level Intermediate Representation (HIR), Abstract Syntax Tree (AST), and fallback matching analysis. Priority is given to using HIR, which has error recovery capabilities, to extract application-side evidence. For source files that HIR fails to process, AST is used to supplement the analysis. For complex source files that still cannot be stably parsed, fallback matching analysis based on string patterns is further employed to improve robustness in handling complex projects and incomplete source code.
[0112] During the extraction of conditional compilation information, a conditional compilation stack is maintained synchronously to record the conditional compilation context. Specifically, when the iterator enters a syntax node with the conditional compilation attribute #[cfg(...)], the conditional expression declared in that attribute is pushed onto the conditional stack; when the iterator leaves the syntax node, the corresponding conditional expression is popped off. The conditional compilation attribute #[cfg(...)] is a Rust attribute used to describe the conditions under which code takes effect, and can be used to limit specific code to participate in compilation only when conditions such as target architecture, target operating system, target features, or compilation features are met. This allows API calls, type paths, macro calls, and use declarations located under different conditional branches to be associated with their actual effective compilation context. Finally, the file path and line number corresponding to each piece of evidence are recorded to form source code location information, providing a basis for subsequent platform-related filtering and feature deduction.
[0113] Based on the above analysis, application-side evidence related to capability derivation is extracted. This application-side evidence includes API call information such as use path references, external library (crate) references, function call expressions, method call expressions, type paths, and macro calls.
[0114] like Figure 4 As shown, for C applications, the processing procedure is as follows:
[0115] First, .c and .h source files under the target application path are recursively collected, with optional reading of explicit capability input files. Then, C differential static analysis is performed on the collected source files. This analysis includes Clang Abstract Syntax Tree (AST) analysis based on the Clang compiler frontend (Clang, C Language Family Frontend) and regular expression fallback matching analysis, prioritizing Clang AST analysis. If compile_commands.json exists, corresponding compilation parameters are further extracted to improve the accuracy of macro definition processing, header file path parsing, and semantic recognition. Upon successful AST analysis, function call entities and their corresponding file locations and line numbers are extracted. For source files that cannot be stably processed by Clang AST analysis, C language application programming interface (API) patterns are loaded from the rule base. The source code is matched line by line using regular expressions with word boundary constraints to continue extracting application-side evidence. During the regular expression backtracking matching analysis, a preprocessing condition stack is maintained simultaneously to record the preprocessing condition context. Specifically, when encountering preprocessing directives such as #ifdef, #ifndef, #if, #elif, #else, and #endif, condition push, condition substitution, condition negation, or condition pop operations are performed respectively. For ordinary lines of code, API pattern recognition is performed under the current preprocessing condition context, and the corresponding capability name, hit position, and condition snapshot are recorded. For evidence obtained through abstract syntax tree analysis or regular expression backtracking matching, the preprocessing conditions that took effect before its current position can be further traced back, and the architecture-related macro expressions are uniformly converted into the condition expression form used for subsequent evaluation.
[0116] In addition, when the system detects network or file descriptor-related capabilities such as net, select, and epoll, it can automatically add file descriptor capabilities (fd) to reduce the risk of capability omissions due to indirect dependencies in C / POSIX scenarios.
[0117] Through differentiated static analysis, a unified application analysis result is obtained, which includes a capability evidence set, source code location information, conditional compilation context, and optional runtime feature information. The capability evidence set refers to the set of evidence extracted from the target application source code and uniformly organized, which can be used for capability inference, rather than simply referring to the abstract capability name itself. For Rust applications, the capability evidence set mainly includes use path references, external library (crate) references, function call expressions, method call expressions, type paths, macro calls, and runtime-related features declared in Cargo.toml. For C applications, the capability evidence set mainly includes function call patterns identified through Clang abstract syntax tree analysis or regular expression backtracking, capability information declared in explicit capability input files, and capability mapping information corresponding to interface pattern matching results. All of the above evidence can be further associated with their corresponding file paths, line numbers, and conditional contexts, thus forming a traceable unified analysis result. Although Rust and C have different source-level structures, after unified organization, both can enter the same subsequent assembly decision process.
[0118] In this invention, the abstract syntax tree analysis based on the Clang compiler frontend is a source code semantic analysis method based on the Clang compiler frontend, which is itself an existing compiler frontend analysis technology. This invention introduces this analysis method into the C application capability evidence extraction process and combines it with regular expression fallback, condition tracking, and subsequent assembly decision.
[0119] Example 4
[0120] A method for minimizing the assembly of application-driven components for a single kernel, as described in Example 3, differs in that, in step S4, a unified conditional expression model is used to uniformly convert the conditional compilation context in Rust applications and the preprocessing conditional context in C applications into conditional expression objects that can be processed together. Specifically:
[0121] For Rust applications, the conditional expressions #[cfg(target_arch = "...")], #[cfg(target_os ="...")], #[cfg(target_feature = "...")], #[cfg(feature = "...")], and not(...), any(...), all(...) are parsed and normalized into target architecture condition TargetArch, target operating system condition TargetOs, target processor feature condition TargetFeature, compilation feature condition Feature, logical NOT, logical OR Any, and logical AND All unified condition types.
[0122] For C applications, preprocessor conditions such as #ifdef, #ifndef, #if, #elif, #else, and #endif are mapped to a unified condition type identical to those in Rust applications after macro identification, logical decomposition, and condition normalization. For example, #ifdef __x86_64__ can be converted to TargetArch("x86_64"), #ifndef __aarch64__ can be converted to Not(TargetArch("aarch64")), and #if defined(A) && defined(B) can be converted to the logical AND condition All(...). Conditional expressions that cannot be further normalized are uniformly denoted as Other. In this way, conditional compilation constraints in different languages can be transformed into the same evaluation object, thus enabling unified processing in the same filtering stage.
[0123] The core of step S4 lies in further limiting "information that has appeared in the source code" to "information that is truly effective for the current target platform," in order to avoid an overly broad scope of capability deduction due to the simultaneous existence of cross-platform code, conditional compilation branches, or placeholder implementations. Evidence without conditional constraints can be directly regarded as being related to the current target platform;
[0124] For evidence with conditional constraints, each item is evaluated in conjunction with the current target context. Specifically, for the target architecture condition `TargetArch`, it is determined whether it matches the current target architecture; for the target operating system condition `TargetOs`, it is determined whether it matches the current target operating system; for the target processor feature condition `TargetFeature`, it is determined whether the current target possesses the corresponding processor feature; for the compilation feature condition `Feature`, it is determined whether the corresponding compilation feature is enabled in the current build context; for logical NOT conditions, its internal sub-conditions are evaluated first, and then the result is inverted; for logical OR `Any`, it is determined to be true as long as any sub-condition is true; for logical AND `All`, it is determined to be true only if all sub-conditions are true. For compilation feature conditions or other conditions whose truth values cannot be determined temporarily, a conservative retention strategy can be adopted, that is, relevant evidence is not deleted for the time being to reduce the risk of missing key capabilities. Through the above evaluation process, irrelevant evidence that only exists in other architectures, other operating systems, or other conditional branches can be excluded, and only information that is truly relevant to the current target platform can be retained, thereby avoiding incorrect capability derivation and reducing the risk of misassembly.
[0125] For example, when the target platform is x86_64, network interface calls that only appear under the condition #[cfg(target_arch = "aarch64")] will be filtered out, preventing incorrect deduction of network function requirements. Similarly, if a call in the C source code is only located under the #ifdef __aarch64__ branch, that call will not participate in solving for the capabilities of the x86_64 target platform.
[0126] like Figure 5 In the unified conditional expression model, TargetArch, TargetOs, TargetFeature, Feature, Not, Any, and All are different condition types used to represent different categories of conditional compilation constraints. Specifically, TargetArch represents the target architecture condition, describing code that only takes effect on a specific processor architecture; TargetOs represents the target operating system condition, describing code that only takes effect on a specific target operating system; TargetFeature represents the target processor feature condition, describing code that only takes effect when the processor has a specific instruction set or hardware feature; Feature represents the compilation feature condition, describing code that only takes effect when a specific compilation feature is enabled; Not represents a logical NOT condition, i.e., negating a condition; Any represents a logical OR condition, meaning any one of multiple conditions is sufficient; and All represents a logical AND condition, meaning multiple conditions must be true simultaneously.
[0127] Example 5
[0128] A method for minimizing the assembly of application-driven components for a single kernel, as described in Example 4, differs in that the present invention employs a structure that separates the analysis engine from the rule base. Figure 6 The analysis engine is responsible for extracting and organizing application-side evidence. Application-side evidence refers to the set of source code evidence extracted and uniformly organized from the target application's source code, including interface call information related to capability derivation, source code location information, conditional context, and optional runtime feature information. Specifically, for Rust applications, application-side evidence can be obtained through analysis of .rs source files and Cargo.toml; for C applications, application-side evidence can be obtained through analysis of .c and .h source files, explicit capability input files, and related compilation information. Framework-specific knowledge is maintained by an external rule base, avoiding the solidification of component rules for a single-kernel framework within the engine. Different rule sets can be switched at runtime via rule directory parameters, allowing the same analysis engine to adapt to different single-kernel systems.
[0129] In step S5, the external rule base includes API-to-feature mapping rules, feature dependency closure rules, platform-to-bus and driver mapping rules, build configuration rules, and feature-to-module mapping rules, as shown in the table below; the aforementioned rules can be used for candidate feature solving, as well as for subsequent build adaptation and report output.
[0130] Table 1. Rule Mapping Rules
[0131]
[0132] In step S5, firstly, based on the API-to-feature mapping rules in the external rule base, the API calls, function symbols, project description file feature declarations, or explicit feature inputs retained after conditional correlation filtering in the application analysis results are converted into a direct feature set, and this direct feature set is used as the initial feature set. The direct features refer to functional features directly obtained only from application-side evidence and API-to-feature mapping rules, excluding low-level dependency features derived from dependency closure rules, and also excluding platform features or driver features added by platform-to-bus and driver mapping rules. Subsequently, transitive expansion is performed based on the closure dependency relationships in the external rule base, and the low-level features necessary for the direct features to run are added to the candidate feature set. After the dependency closure is solved, platform-related completion is further performed in conjunction with the target platform information. If the bus type is explicitly given in the analysis results, the corresponding bus feature is added to the candidate feature set. If the rule base defines driver features for the current platform and current capability combination, the driver features are added to the candidate feature set.
[0133] Therefore, the candidate feature set not only covers the functional requirements reflected by direct application calls, but also the underlying assembly items required when the function is actually implemented on the target platform.
[0134] Example 6
[0135] A method for minimizing the assembly of application-driven components for a single kernel, as described in Embodiment 5, differs in that, in step S6, a first-level rule-based minimization is performed on the candidate feature set obtained in step S5. That is, without invoking actual build verification, the candidate set is pruned according to rules based on source code evidence, direct capability requirements, dependencies, and platform necessities to remove obviously redundant features and reduce the search space for subsequent verification-based trial deletion.
[0136] like Figure 7 As shown, the implementation process of minimizing the first-level regular expression in step S6 is as follows: ① First, extract the set of evidence capabilities with source code location information from the application analysis results, and combine it with the set of candidate features generated in step S5 to establish the decision boundary for retention: all features that are supported by direct source code evidence, or features that belong to direct capability mapping results, closure dependency results, or platform-driven completion results are considered as features that should not be deleted in the current stage. ② Features used to describe platform bus type or device driver type, such as bus features and driver class features, can be directly retained. The reason is that although these features may not correspond to direct call information in the application source code, they are usually derived from platform rules and are necessary configuration items required for successful construction of the target platform and device access. Features that do not meet conditions ① or ② are marked as redundant features and removed from the candidate feature set. The reason and name of the removal are recorded to create a traceable pruning record in the report. The result obtained after this step can be used as input for the second-level verification-based trial-and-error minimization, or it can be directly output as the final assembly result when verification mode is off.
[0137] Example 7
[0138] A method for minimizing the assembly of application-driven components for a single kernel, as described in Example 6, differs in that, in step S7, as... Figure 7 The implementation process of verification-based trial deletion minimization is as follows:
[0139] First, construct a set of essential features that cannot be attempted to be deleted. This set includes basic dependency features obtained from dependency closure solving, driver features obtained from platform driver completion, and structural features with bus or driver prefixes. These features typically serve as underlying dependencies, platform adaptations, or device access mechanisms. If they are attempted to be deleted rashly, it may lead to a large number of meaningless verification failures. Therefore, they are directly excluded from the scope of attempted deletion in this step.
[0140] After determining the necessary feature set, the remaining features constitute the candidate deletion set, i.e., non-essential features. Subsequently, deletion is performed item by item in the candidate deletion set in a predetermined order. For each feature to be deleted, a temporary experimental feature set after deleting the feature is generated and injected into the target construction process for verification. If the verification is successful, it means that the feature to be deleted is not necessary to maintain the current construction result, and it is removed from the current feature set. If the verification fails, the feature to be deleted is restored and the next feature to be deleted is processed until all candidate deletion sets have been deleted, and finally the minimum feature set is formed.
[0141] Preferably, the verification process employs a single verification mode, which is one of the following: compilation verification, test verification, virtual machine startup verification, or service port detection verification. These verification processes and their pass / fail determination methods are all existing technologies. Compilation verification is based on the successful completion of the build process. Test verification, in addition to successful build, further requires successful execution of the test command. Virtual machine startup verification requires valid startup output within a limited time after the image starts. Service port detection verification requires that a connection to the target port be successfully established after the image starts. Finally, step S7 outputs the minimized result obtained under the constraints of the selected verification mode, rather than a pure rule derivation result detached from the actual build conditions.
[0142] Example 8
[0143] A method for minimizing the assembly of application-driven components for a single kernel, as described in Example 7, differs in that, in step S8, firstly, the minimum feature set is filtered according to the output filtering rules in the external rule base, removing features that do not need to be directly output, and the filtered features are written to the feature list file features.txt in comma-separated form for the build system to read directly; secondly, according to the predefined environment variable mapping relationship in the external rule base, the minimum feature set is further converted into build variables or configuration fragments, generating the environment variable file env.mk for the build system to load and use in subsequent build processes, wherein each variable can be protected to avoid overwriting the configuration explicitly specified by the user; thus, the aforementioned analysis and decision results are transformed from an internally derived state into input artifacts that the build system can directly use, realizing a closed loop from automatic assembly results to actual image build; when report output is not enabled, a summary file summary.txt is further generated, which includes the target application, language type, target platform, and the final minimum feature set, for the build script or manual viewing of the analysis results, such as Figure 8 As shown.
[0144] The generated minimized image includes the following forms: ①Features.txt file: Features are written to the file in comma-separated form for the build system to read and override the FEATURES variable; certain features can be excluded according to the output filtering mode defined in the rules, such as driving features that can be automatically derived from other features in the target framework; ② Environment variable file env.mk; Based on the environment variable mapping in the external rule base, features are converted into build system environment variables. Each environment variable is protected by the $(origin) protection mechanism and only takes effect when the user does not explicitly set it through the command line, so as to avoid overwriting the user's manual configuration. ③ Summary file summary.txt; when report output is not enabled, a summary file is generated. The summary file includes the target application, language type, target platform and final feature set, for script building or manual review of analysis results.
[0145] In the extended form, for frameworks using the Kconfig configuration system, the feature can be further mapped to CONFIG_ Variables or other configuration fragments. Further, step S8 may also be performed by the build adaptation layer, which may generate build commands, working directories, and additional parameters according to the conventions of the target framework, and inject the artifacts as intermediate inputs into make, cargo, scripted builders, or virtual machine startup scripts.
[0146] Example 9
[0147] A method for minimizing the assembly of application-driven components for a single kernel, as described in Example 8, differs in that, in step S9, the output of the assembly report includes a structured report (JSON) and a human-readable report (Markdown). The structured report (JSON) corresponds to a structured report file, used to record structured content such as application path, language type, target platform, capability set, API call evidence, condition information, feature sets of each stage, module set, and build results. The human-readable report (Markdown) corresponds to a human-readable report file, used to display the assembly process, evidence sources, trimming records, and final output results in a readable manner.
[0148] The assembly result includes at least a final feature set file and a summary file. When report output or build output is enabled, a structured report and a human-readable report can also be generated. Through the above output information, developers can clearly see the source, dependencies, trimming process, and corresponding build status of each final feature, thus forming a complete audit chain from the source code location to the assembly result.
[0149] Example 10
[0150] A method for minimizing the assembly of application-driven components for a single kernel, as described in Example 1, is applied to the independent analysis of Rust HTTP service applications in ArceOS (x86-pc platform). In this example, the actual project path is / arceos / examples / httpserver, which contains Cargo.toml and src / main.rs, and is a typical Rust single-kernel network service application.
[0151] Input information: Target application: / arceos / examples / httpserver Target platform: x86-pc Target architecture: x86_64 Rules directory: / miniasm / rules / arceos-rules
[0152] The steps are as follows: Speech recognition: The system detected the existence of the Cargo.toml file in the target application directory and identified it as a Rust application; Static analysis: The system first reads Cargo.toml, which declares the following dependencies: [dependencies] axstd = { workspace = true, features = ["alloc", "multitask", "net"], optional = true} The explicit capabilities input from this statement are alloc, multitask, and net.
[0153] Subsequently, the system performs HIR multi-stage parsing on src / main.rs. This source file contains the following key API calls: use std::net::{TcpListener, TcpStream}; — Network-related source code information use std::thread; — Source code information related to multitasking let response = format!(...) — Source code information related to dynamic memory allocation thread::spawn(move || ...) — Source code information related to multitasking thread::spawn(...) — Source code information related to multitasking.
[0154] The system successfully extracted all the above source code information using the HIR parser (log shows [hir] parsed 1files via ra_ap_syntax), without needing to fall back to the AST or string matching stage.
[0155] Conditional compilation filtering: Since the source code of this embodiment does not contain conditional compilation attributes such as #[cfg(target_arch = "...")], the conditional context of all extracted information is empty, so all of it passes the relevance filtering.
[0156] Candidate feature solving: According to the rule file under rules / arceos-rules / , the system performs the following calculations, as shown in Table 2:
[0157] Table 2 Solution Process Table
[0158]
[0159] Regularity minimization: The system checks whether each feature has source code information or belongs to a required category: alloc: Includes Cargo.toml and format! Information support → Reserved fs: Supported by read_dir information → Reserved multitask: Supported by Cargo.toml and thread::spawn information → Reserved net: Supported by Cargo.toml and std::net:: information → Reserved paging: for closure dependencies → Retain bus-PCI: Bus feature → Reserved driver-ixgbe: Driver feature → Reserved Trimmed features are cropped, trimmed_features = []; Output verification (actual execution result): Execute command: cargo run --release -- analyze \ --app / arceos / examples / httpserver \ --plat x86-pc --arch x86_64 \ --rules-dir / miniasm / rules / arceos-rules \ --output-dir / tmp / miniasm-httpserver --report Actual console output: Language: rust Capabilities: alloc, fs, multitask, net Features: alloc, bus-pci, driver-ixgbe, fs, multitask, net, paging Modules: axalloc, axconfig, axdriver, axfs, axhal, axlog, axmm, axnet, axruntime, axsync, axtask The generated features.txt file contains: alloc,bus-pci,driver-ixgbe,fs,multitask,net,paging The generated env.mk file contains: # Auto-generated by miniasm. Do not edit. ifneq ($(origin BLK),command line) BLK := y endif ifneq ($(origin NET),command line) NET := y endif The generated summary.txt file contains: app= / arceos / examples / httpserver language=rust platform=x86-pc features=alloc,bus-pci,driver-ixgbe,fs,multitask,net,paging The generated JSON report contains complete evidence tracing: { "api_evidence": { "alloc": [ "Cargo.toml axstd features", "src / main.rs:66 -> format! (HIR)" ], "multitask": [ "Cargo.toml axstd features", "src / main.rs:64 -> std::thread::spawn (HIR)", "src / main.rs:81 -> thread::spawn (HIR)" ], "net": [ "Cargo.toml axstd features", "src / main.rs:16 -> std::net:: (HIR)" ] } }
[0160] Example 11
[0161] A minimal assembly method for application-driven components for a single kernel, as described in Example 1, is applied to the differentiated assembly (aarch64-qemu-virt) of the same Rust HTTP service application on different platforms. This example uses the same target application as Example 10, but the target platform is switched to aarch64-qemu-virt, which is used to illustrate how the present invention automatically generates different assembly schemes according to platform differences.
[0162] Input information: Target application: / arceos / examples / httpserver (same as Example 10) Target platform: aarch64-qemu-virt Target architecture: aarch64 Rules directory: / miniasm / rules / arceos-rules Actual commands executed and output: cargo run --release -- analyze \ --app / arceos / examples / httpserver \ --plat aarch64-qemu-virt --arch aarch64 \ --rules-dir / miniasm / rules / arceos-rules \ --output-dir / tmp / miniasm-httpserver-aarch64 Actual console output: Language: rust Capabilities: alloc, fs, multitask, net Features: alloc, bus-mmio, driver-virtio-net, fs, multitask, net, paging Modules: axalloc, axconfig, axdriver, axfs, axhal, axlog, axmm, axnet, axruntime, axsync, axtask
[0163] The comparison between this embodiment and Embodiment 10 is shown in Table 3.
[0164] Table 3 Comparison of Example 10 and Example 11
[0165]
[0166] Analysis results of the two platforms on the same application show that:
[0167] The initial features and closure features are exactly the same because the application source code is the same and the extracted API call information remains unchanged;
[0168] Bus characteristics and driver characteristics switch automatically with the platform; x86-pc uses the PCI bus and ixgbe driver, while aarch64-qemu-virt uses the MMIO bus and virtio-net driver.
[0169] The env.mk file additionally outputs BUS := mmio, which helps the build system to correctly select the bus initialization logic;
[0170] Because `exclude_patterns = ["driver-virtio-` is defined in `build_config.toml`. In features.txt, driver-virtio-net is filtered out, and the actual features.txt written is alloc,bus-mmio,fs,multitask,net, paging.
[0171] This embodiment verifies the ability of the present invention to automatically adapt driver and bus features on different platforms without the need for manual reconfiguration.
[0172] Example 12
[0173] A method for minimizing the assembly of application-driven components for a single kernel, as described in Example 1, except that it is for the analysis and construction of Unikraft applications.
[0174] This embodiment, in conjunction with / app-helloworld, / app-helloworld-rust, and the Unikraft usage described in doc / usage_guide.md, illustrates the adaptation method of this invention in another type of monolithic kernel system.
[0175] For ` / app-helloworld`, since `Cargo.toml` is not present in the application directory, the system identifies it as a C application and performs a two-stage analysis on `main.c`, prioritizing Clang AST and supplementing with regular expression fallback. This sample mainly contains `printf("Hello world!\n");` and calls to `nanosleep` and `fflush` in the conditional compilation branch, making it suitable as a verification example for C application identification, preprocessing condition tracing, and basic artifact output. For ` / app-helloworld-rust`, since `Cargo.toml` exists in the directory, the system identifies it as a Rust application and enters the Rust analysis chain.
[0176] In this embodiment, the system receives the following input: Build directory: / unikraft Target application: / app-helloworld Target platform: KVM Target architecture: x86_64 Rules directory: / miniasm / rules / unikraft-rules Users can initiate the following build commands from the Unikraft directory: make A= / app-helloworld AUTO_FEATURES=y PLAT=kvm ARCH=x86_64 Based on the current rules directory rules / unikraft-rules, the system generates features.txt, summary.txt, and env.mk in the output directory. The environment variables in env.mk are typically in the form of CONFIG_LIBUKNETDEV=y, CONFIG_LIBPOSIX_SOCKET=y, CONFIG_LIBUKALLOC=y, etc., and can be used as bridging inputs for Unikraft build scripts. Since Unikraft requires the A= parameter to use an absolute path, this invention retains this constraint within this framework without altering the user's original build entry point.
[0177] This embodiment shows that:
[0178] The same analytics engine can be adapted to a different build system than ArceOS;
[0179] For C and Rust applications, the system will continue to use the existing language recognition and static analysis links, respectively.
[0180] By changing the rule directory, the build variables in the output artifact can be automatically switched from ArceOS-style NET=y, BUS=mmio to Unikraft-style CONFIG_LIB. variable;
[0181] Therefore, this invention can reuse the same assembly decision-making capability in two different frameworks, ArceOS and Unikraft, using a "general analysis engine + external rule catalog" approach.
[0182] Example 13
[0183] A minimal assembly system for application-driven components oriented to a single kernel, such as Figure 2 ,include:
[0184] The input acquisition module is used to acquire the target application path, target platform identifier, architecture coverage information, bus information, verification mode, probe port, report output directory, and rule directory path;
[0185] The language recognition module is used to determine the language type of the target application based on the project description file;
[0186] The Rust source code analysis module is used to extract API call information based on high-level intermediate representation parsing and abstract syntax tree parsing, and to fall back to string matching when necessary, while maintaining the conditional compilation stack;
[0187] The C source code analysis module is used for abstract syntax tree analysis and regular expression backtracking matching based on the Clang compilation front-end to extract API call information, and synchronously maintains the preprocessing condition stack;
[0188] The conditional filtering module is used to perform target architecture relevance filtering on API call information based on a unified conditional expression model;
[0189] The analysis results module is used to generate application analysis results that include a set of functional requirements, source mapping, and operational characteristics.
[0190] The rule loading module is used to load API mapping rules, feature dependency closure rules, platform-to-bus and driver mapping rules, build rules, and feature-to-module rules from external rule bases;
[0191] The dependency closure solving module is used to perform transitive dependency unrolling based on feature-based dependency closure rules;
[0192] The platform driver completion module is used to supplement bus features and driver features based on the platform-to-bus and driver mapping rules and the current set of functional requirements.
[0193] The rule-based minimization module is used to remove redundant features that lack supporting evidence based on source code information;
[0194] The verification-based minimization module is used to attempt deletions item by item and determine whether a feature can be deleted by constructing a verification module.
[0195] Build an adaptation module to convert the final feature set into a configuration format acceptable to the target build system and inject it into the build chain;
[0196] The report generation module is used to output structured reports in JSON format and human-readable reports in Markdown format.
[0197] The modules described above can be deployed on the same electronic device or, functionally, across multiple collaborative nodes. For example, the source code analysis module and the conditional filtering module can be deployed on the development host, while the verification-based minimization module and the build adaptation module can be deployed on a continuous integration environment or a remote build node. Modules can exchange data via files, command-line arguments, memory objects, or structured messages.
[0198] The assembly decision engine is comprised of a language recognition module, a source code analysis module, a conditional filtering module, a rule loading module, a candidate feature solving module, and a minimization module, while the adaptation module and the report generation module constitute the delivery output layer. This modular division allows for migration and adaptation to different monolithic systems without altering the core logic of the analysis engine, simply by replacing the rule files and building the adaptation layer.
[0199] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for minimizing the assembly of application-driven components for a single kernel, characterized in that, Includes the following steps: S1, obtain the target application path, target platform identifier, architecture coverage information, bus information, verification mode, probe port, report output directory, and rule directory path; S2 identifies the language type of the target application and selects the corresponding analysis strategy based on the language type; S3 performs cross-language differential static analysis on the target application source code, identifies API call information, records corresponding conditional compilation constraints, and forms application analysis results; S4, based on the unified conditional expression model and combined with target architecture information, performs platform-related filtering on API call information, thereby filtering out irrelevant evidence; S5 maps the filtered application analysis results to the initial feature set based on the external rule base, and generates a candidate feature set through dependency closure solving and platform-driven completion. S6 performs first-level rule-based minimization on the candidate feature set, removing redundant features that lack source code information support and are neither dependent nor platform-essential. S7, perform the second-level verification-based trial deletion minimization on the feature set after the first-level regular minimization, delete candidate features one by one and call the construction process to verify, so as to obtain the minimum feature set that has further converged; S8 transforms the minimum feature set into a configuration form acceptable to the target build system, injects it into the single-kernel build chain, and generates a minimal image; S9 outputs the assembly results and assembly report; the assembly report includes API call information, conditional evidence set, feature set of each stage, trimming record, module set and construction results.
2. The method for minimizing the assembly of application-driven components for a single kernel according to claim 1, characterized in that, In step S2, the system determines the language type based on the project description file in the target application path. If a Cargo.toml file exists in the target application directory, it is identified as a Rust application; otherwise, it is identified as a C application. For Rust applications, perform Rust differential static analysis; for C applications, perform C differential static analysis.
3. The method for minimizing the assembly of application-driven components for a single kernel according to claim 2, characterized in that, In step S3, for Rust applications, Rust differential static analysis includes high-level intermediate representation parsing, abstract syntax tree parsing, and fallback matching analysis. Among them, high-level intermediate representation parsing with error recovery capability is used to extract application-side evidence. For source files that high-level intermediate representation parsing fails to process, abstract syntax tree parsing is used to continue the analysis. For complex source files that still cannot be parsed stably, fallback matching analysis based on string patterns is used to improve the robustness of handling complex projects and incomplete source code. During the extraction of conditional compilation information, the conditional compilation stack is maintained synchronously to record the conditional compilation context; For C applications, the processing procedure is as follows: First, the .c and .h source files under the target application path are recursively collected, and explicit capability input files are read. Then, C differential static analysis is performed on the collected source files. This analysis includes abstract syntax tree analysis based on the Clang compiler frontend and regular expression fallback matching analysis. Specifically, abstract syntax tree analysis based on the Clang compiler frontend is used. If compile_commands.json exists, the corresponding compilation parameters are extracted to improve the accuracy of macro definition processing, header file path parsing, and semantic recognition. If abstract syntax tree analysis is successful, function call entities and their corresponding file locations and line numbers are extracted. For source files that cannot be stably processed by abstract syntax tree analysis based on the Clang compiler frontend, C language application interface patterns are loaded from the rule base, and the source code is matched line by line using regular expressions with word boundary constraints to continue extracting application-side evidence. During regular expression fallback matching analysis, a preprocessing condition stack is maintained synchronously to record the preprocessing condition context. Through differentiated static analysis, application analysis results in a unified format are obtained. These results include capability evidence sets, source code location information, conditional compilation context, and optional runtime feature information.
4. The method for minimizing the assembly of application-driven components for a single kernel according to claim 3, characterized in that, In step S4, the unified conditional expression model is used to convert the conditional compilation context in Rust applications and the preprocessing conditional context in C applications into conditional expression objects that can be processed together. Specifically: For Rust applications, conditional expressions are parsed and normalized into a unified condition type: TargetArch, TargetOs, TargetFeature, Compiler Feature, Logical NOT, Logical OR Any, and Logical AND All. For C applications, the preprocessed conditions are mapped to a unified condition type that is the same as the conditions in Rust applications after macro recognition, logical splitting, and condition normalization. Evidence without any conditions or constraints is directly considered to be related to the current target platform; For evidence with conditional constraints, each item is evaluated in conjunction with the current target context. Specifically, for the target architecture condition TargetArch, it is determined whether it is consistent with the current target architecture; for the target operating system condition TargetOs, it is determined whether it is consistent with the current target operating system; for the target processor feature condition TargetFeature, it is determined whether the current target has the corresponding processor feature; for the compilation feature condition Feature, it is determined whether the corresponding compilation feature is enabled in the current build context; for logical NOT, its internal sub-conditions are evaluated first, and then the result is inverted; for logical OR Any, it is determined to be true as long as any sub-condition is true; for logical AND All, it is determined to be true only if all sub-conditions are true.
5. The method for minimizing the assembly of application-driven components for a single kernel according to claim 4, characterized in that, In step S5, the external rule base refers to a collection of rule files that are maintained independently of the analysis engine and loaded at runtime through the rule directory path. The external rule base includes API-to-feature mapping rules, feature dependency closure rules, platform-to-bus and driver mapping rules, build configuration rules, and feature-to-module mapping rules. In step S5, firstly, based on the API-to-feature mapping rules in the external rule base, the API calls, function symbols, project description file feature declarations, or explicit feature inputs retained after conditional correlation filtering in the application analysis results are converted into a direct feature set, and this direct feature set is used as the initial feature set; then, based on the closure dependency relationship in the external rule base, transitive expansion is performed to supplement the candidate feature set with the underlying features necessary for the direct feature runtime. After the dependency closure is solved, platform-related completion is performed in conjunction with the target platform information; if the bus type is explicitly given in the analysis results, the corresponding bus feature is added to the candidate feature set; if the rule base defines driving features for the current platform and the current capability combination, the driving features are added to the candidate feature set.
6. The method for minimizing the assembly of application-driven components for a single kernel according to claim 5, characterized in that, The process of minimizing the first-level regularity in step S6 is as follows: ① First, extract the set of evidence capabilities with source code location information from the application analysis results, and combine it with the set of candidate features generated in step S5 to establish the decision boundary for retention: all features that are supported by direct source code evidence, or features that belong to direct capability mapping results, closure dependency results, or platform-driven completion results are considered as features that should not be deleted in the current stage. ②Features used to describe platform bus type or device driver type are directly retained; For features that do not meet conditions ① or ②, mark them as redundant features and remove them from the candidate feature set, while recording the reason and name for removal.
7. The method for minimizing the assembly of application-driven components for a single kernel according to claim 6, characterized in that, In step S7, the implementation process of verification-based trial deletion minimization is as follows: First, construct the necessary feature set, which includes basic dependency features obtained from dependency closure solving, driver features obtained from platform driver completion, and structural features with bus or driver prefixes. After determining the necessary feature set, the remaining features constitute the candidate deletion set, i.e., non-essential features. Subsequently, deletion is performed item by item in the candidate deletion set in a predetermined order. For each feature to be deleted, a temporary experimental feature set after deleting the feature is generated and injected into the target construction process for verification. If the verification is successful, it means that the feature to be deleted is not necessary to maintain the current construction result, and it is removed from the current feature set. If the verification fails, the feature to be deleted is restored and the next feature to be deleted is processed until all candidate deletion sets have been deleted, and finally the minimum feature set is formed. The verification process is executed in a single verification mode, which is one of the following: compilation verification, test verification, virtual machine startup verification, or service port detection verification.
8. The method for minimizing the assembly of application-driven components for a single kernel according to claim 7, characterized in that, In step S8, firstly, the minimum feature set is filtered according to the output filtering rules in the external rule base, removing features that do not need to be directly output, and the filtered features are written to the feature list file features.txt in comma-separated form for the build system to read directly. Secondly, based on the predefined environment variable mapping relationship in the external rule base, the minimum feature set is further converted into build variables or configuration fragments, generating the environment variable file env.mk for the build system to load and use in subsequent build processes. When report output is not enabled, a summary file summary.txt is generated, which includes the target application, language type, target platform, and the final minimum feature set, for the build script or manual review of the analysis results.
9. The method for minimizing the assembly of application-driven components for a single kernel according to claim 8, characterized in that, In step S9, the assembly report output includes a structured report (JSON) and a human-readable report (Markdown). The structured report (JSON) corresponds to a structured report file, which records the application path, language type, target platform, capability set, API call evidence, condition information, feature set of each stage, module set, and structured content of the build result. The human-readable report (Markdown) corresponds to a human-readable report file, which is used to display the assembly process, evidence source, trimming records, and final output results in a readable manner. The assembly result includes at least a final feature set file and a summary file.
10. A minimal component assembly system for a single-kernel application-driven architecture, characterized in that, include: The input acquisition module is used to acquire the target application path, target platform identifier, architecture coverage information, bus information, verification mode, probe port, report output directory, and rule directory path; The language recognition module is used to determine the language type of the target application based on the project description file; The Rust source code analysis module is used to extract API call information based on high-level intermediate representation parsing and abstract syntax tree parsing, and to fall back to string matching when necessary, while maintaining the conditional compilation stack; The C source code analysis module is used for abstract syntax tree analysis and regular expression backtracking matching based on the Clang compilation front-end to extract API call information, and synchronously maintains the preprocessing condition stack; The conditional filtering module is used to perform target architecture relevance filtering on API call information based on a unified conditional expression model; The analysis results module is used to generate application analysis results that include a set of functional requirements, source mapping, and operational characteristics. The rule loading module is used to load API mapping rules, feature dependency closure rules, platform-to-bus and driver mapping rules, build rules, and feature-to-module rules from external rule bases; The dependency closure solving module is used to perform transitive dependency unrolling based on feature-based dependency closure rules; The platform driver completion module is used to supplement bus features and driver features based on the platform-to-bus and driver mapping rules and the current set of functional requirements. The rule-based minimization module is used to remove redundant features that lack supporting evidence based on source code information; The verification-based minimization module is used to attempt deletions item by item and determine whether a feature can be deleted by constructing a verification module. Build an adaptation module to convert the final feature set into a configuration format acceptable to the target build system and inject it into the build chain; The report generation module is used to output structured reports in JSON format and human-readable reports in Markdown format.
