Compiling method, device and equipment, readable storage medium and vehicle
By obtaining C++ and Rust source code, generating static libraries and using dependent libraries and environment variables to compile Rust code, the problem of C++ and Rust code compilation compatibility in smart car software is solved and an efficient compilation process is achieved.
Patent Information
- Application Number
- CN202310189149.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-22
- Publication Date
- 2024-08-23
AI Technical Summary
Existing technology cannot effectively compile codes written in C++ and Rust programming languages, resulting in compatibility issues during integration development in smart car software engineering.
By obtaining the C++ and Rust source codes in the engineering project, compiling them separately to generate static libraries, and using the pre-obtained dependent libraries and environment variables to compile the Rust source codes, generate target code, and realize code compilation of the two programming languages.
It realizes the compilation of C++ and Rust codes, reduces user operations, improves compilation efficiency, and enables effective compilation of engineering projects with two incompatible programming languages.
Smart Images

Figure CN118535162A
Abstract
Description
Technical Field
[0001] The present application relates to the field of vehicle technology, and in particular to a compilation method, device, equipment, readable storage medium and vehicle. Background Art
[0002] At present, most automotive software is developed in C++, using the engineering management and compilation methods of C++ project development. Rust is an extremely sophisticated system-level language that aims to replace C++. In recent years, based on its high performance and high security, Rust has quickly entered fields with high performance and security requirements, such as automotive software development. Rust's engineering management method is completely different from C++'s engineering management method. For example, Rust and C++ source code compilation methods are different.
[0003] Currently, when an engineering project is written in C++, after the introduction of Rust, the incompatibility between C++ and Rust makes it impossible to compile the codes written in the two programming languages. Summary of the invention
[0004] The present application provides a compilation method, apparatus, device, readable storage medium and vehicle, which are used to solve the problem that an engineering project cannot be compiled when the code is written in two programming languages.
[0005] In order to solve the above problems, the first aspect of the present application provides a compilation method, the method comprising:
[0006] Obtaining a first source code and a second source code in a project, wherein the first source code is written in a first programming language, and the second source code is written in a second programming language, the project is used to implement at least one software function, and the first programming language and the second programming language are incompatible;
[0007] Compiling the first source code to obtain a static library;
[0008] The second source code is compiled according to the static library, the pre-acquired dependent library on which the second source code depends, and the pre-acquired environment variables to obtain a target code.
[0009] A second aspect of the present application provides a compiling device, the device comprising:
[0010] An acquisition module, configured to acquire a first source code and a second source code in a project, wherein the first source code is written in a first programming language, and the second source code is written in a second programming language, the project is used to implement at least one software function, and the first programming language and the second programming language are incompatible;
[0011] A first compiling module, used for compiling the first source code to obtain a static library;
[0012] The second compiling module is used to compile the second source code according to the static library, the pre-acquired dependent library on which the second source code depends, and the pre-acquired environment variables to obtain the target code.
[0013] A third aspect of the present application provides a compilation device, the device comprising a processor and a memory, the memory storing a program or instruction that can be run on the processor, and the program or instruction, when executed by the processor, implements the steps of the compilation method described in the first aspect.
[0014] A fourth aspect of the present application provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the compilation method described in the first aspect are implemented.
[0015] A fifth aspect of the present application provides a vehicle, the vehicle comprising a vehicle-mounted system, and the vehicle-mounted system, when executed, is used to implement the steps of the compilation method described in the first aspect.
[0016] The method provided in the embodiment of the present application obtains a first source code and a second source code in an engineering project, wherein the first source code is written in a first programming language, and the second source code is written in a second programming language, and the engineering project is used to implement at least one software function; compiles the first source code to obtain a static library; compiles the second source code according to the static library, the dependent library on which the pre-acquired second source code depends, and the pre-acquired environment variables to obtain a target code. In the above manner, the first source code written in the first programming language can be compiled first, and then the second source code written in the second programming language can be compiled based on the static library obtained by the compilation. By separately compiling the source codes written in two incompatible programming languages, the engineering project written in the first programming language and the second programming language can be compiled. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A schematic diagram of a process flow of a compilation method provided in an embodiment of the present application;
[0018] Figure 2 Another schematic diagram of the compilation method provided in the embodiment of the present application;
[0019] Figure 3 A structural diagram of a compiling device provided in an embodiment of the present application;
[0020] Figure 4 A structural diagram of the compilation device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0021] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the scheme of the present application will be further described below. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.
[0022] In the following description, many specific details are set forth to facilitate a full understanding of the present application, but the present application may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only part of the embodiments of the present application, rather than all of the embodiments.
[0023] At present, most automotive software is developed in C++, using the engineering management and compilation methods of C++ project development. In recent years, Rust has rapidly entered fields with high performance and safety requirements, such as automotive software development, based on its own high performance and high security. Rust has its own project management method, which is completely different from the engineering management method of C++. At present, when intelligent automotive software engineering adopts C++, after introducing Rust fusion development, how to make Rust's engineering management method compatible with the existing C++ engineering method faces many problems, such as:
[0024] Rust and C++ have completely different dependency management methods: Rust uses cargo to complete all dependency management, which is powerful, while C++ needs to rely on the third-party conan to manage dependencies;
[0025] Rust and C++ depend on different library servers: Rust has its own library dependency and release server, while C++ depends on a Conan-compatible artifactory server implementation;
[0026] Rust and C++ source code are compiled differently: Rust uses cargo for unified compilation, while C++ mostly uses Cmake with compilation scripts to manage compilation;
[0027] The compilation parameter setting methods of Rust and C++ are different: Rust uses cargo for unified compilation and has a complete set of compilation parameter setting methods, while C++ currently has no unified method and requires the use of compilation scripts, Cmake, environment variables, etc.
[0028] In a smart car software project, if C++ and Rust need to be integrated for development, there will be two completely different sets of codes, Rust and C++, in the project. The existing compilation method cannot compile projects that use two programming languages.
[0029] Based on this, an embodiment of the present application provides a compilation method, which includes the following steps 101 to 103, wherein:
[0030] Step 101: Obtain a first source code and a second source code in a project, wherein the first source code is written in a first programming language, and the second source code is written in a second programming language, and the first programming language and the second programming language are incompatible.
[0031] The engineering project includes two code files, one code file includes a first source code written in a first programming language, and the other code file includes a second source code written in a second programming language. In this application, the first programming language is C++ and the second programming language is Rust as an example, but it does not constitute a limitation.
[0032] The engineering project can be used to implement at least one software function, for example, a function of playing songs, a function of adjusting the temperature of an air conditioner, and so on.
[0033] Step 102: compile the first source code to obtain a static library.
[0034] When the first source code is compiled, the first source code may be compiled using a dependent library on which the first source code depends to obtain a static library, which is a binary program.
[0035] Optionally, step 102 may include the following steps:
[0036] Obtaining a dependent library on which the first source code depends, and adding the library to a dependent directory of the engineering project;
[0037] According to the dynamic library of the first source code in the dependent directory, the first source code is compiled to obtain a static library.
[0038] Specifically, the dependency library on which the first source code depends refers to the dependency library used by the first source code. The dependency library can be a static library or a dynamic library. The static library can also be called a static library file. Similarly, the dynamic library can also be called a dynamic library file. When obtaining the dependency library on which the first source code depends, the dependency library on which the first source code depends can be determined according to the configuration file of the engineering project, and the dependency library on which the first source code depends can be obtained. The dependency library can be obtained locally or downloaded from the network. Specifically, the dependency library on which the first source code depends can be downloaded from the package management server. For example, if the Rust project needs to rely on C++ code implemented by a third party, the dependent third-party C++ code can be compiled into an independent dynamic library or static library and uploaded to the package management server in advance. Before the Rust project is compiled, the conan function module detects the third-party C++ dependency specified by the project based on the configuration file inside the engineering project. If a dependency configuration is found, the compiled C++ dynamic library file will be automatically downloaded to the local and added to the dependency directory of the engineering project, so that when the first source code is compiled, the dynamic library of the first source code can be obtained from the dependency directory.
[0039] Step 103: compile the second source code according to the static library, the pre-acquired dependent library on which the second source code depends, and the pre-acquired environment variables to obtain a target code.
[0040] The environment variables can be obtained by converting the compilation parameters, which include configuration parameters, local path parameters of the third-party library that the project depends on, and property setting parameters of the project. The configuration parameters include at least one of the compilation type, hardware platform, and vehicle model. The compilation type can be debug, release, etc., and the hardware platform can be x64, s32g, j5, etc. The process of determining the environment variables needs to be performed before compiling the second source code. Optionally, the configuration parameters are configured through a compilation script, which is the entry point for compiling the entire project and provides unified parameter input and configuration.
[0041] For example, if the second source code is a code written in Rust language, the dependent library on which the second source code depends is a Rust library, including a dynamic library or a static library. The dependent library on which the second source code depends can be downloaded from the Gitlab code management server.
[0042] After the second source code is compiled, an executable target code is generated according to the project attributes. Optionally, after step 103, the method further includes: storing the dynamic library composed of the target code in the package management server to achieve the sharing of the target code, and other personnel can download the target code from the package management server for use according to actual needs.
[0043] The method in this embodiment obtains the first source code and the second source code in the engineering project, the first source code is written in the first programming language, the second source code is written in the second programming language, and the engineering project is used to implement at least one software function; compiles the first source code to obtain a static library; compiles the second source code according to the static library, the dependent library on which the pre-acquired second source code depends, and the pre-acquired environment variables to obtain the target code. In the above manner, the first source code written in the first programming language can be compiled first, and then the second source code written in the second programming language can be compiled based on the static library obtained by the compilation. By separately compiling the source codes written in the two incompatible programming languages, the engineering project written in the first programming language and the second programming language can be compiled. Further, by adopting the above steps, in the compilation process, the difference between the codes written in the two languages when compiled separately is not considered. This compilation method is transparent and imperceptible to the upper-level users, which can reduce user operations and thus improve compilation efficiency.
[0044] The following takes C++ as the first programming language and Rust as the second programming language as an example to illustrate the compilation method provided in this application. Figure 2 The example provided in the present application is shown as follows: Figure 2 As shown, the compilation method provided by this application requires the following parts to cooperate and complete:
[0045] (1) Compile the script:
[0046] The build script build.sh is the entry point for the entire project compilation. It provides unified parameter input and configuration, and mainly implements the specification of configuration parameters, including:
[0047] Compilation type: debug, release, etc.
[0048] Hardware platform: x64, s32g, j5, etc.
[0049] Applicable models: x01, x02, x03, etc.
[0050] build.sh finally collects all compilation parameters and compilation configurations set by the user, and then inputs them into the lower-level C++ package management module to build and compile the project source code.
[0051] (2) C++ package management module:
[0052] The C++ package management module is created based on the conan C++ package management tool system, but in this solution conan does not participate in the specific compilation process of the system. Conan has two uses in the solution framework:
[0053] 1. It is used to manage and download Rust projects, which require the use of third-party C++ libraries;
[0054] If the Rust project needs to rely on C++ code implemented by a third party, you can compile the dependent third-party C++ code into an independent dynamic library or static library program and upload it to the package management server in advance. Before compiling the Rust project, the conan function module first detects the third-party C++ dependencies specified by the project based on the configuration files inside the project. If a dependency configuration is found, it will automatically download the compiled C++ dynamic library file to the local computer and add it to the project dependency directory.
[0055] 2. Used to upload the compiled Rust binary program to the conan package management server for use by other C++ programs;
[0056] After the Rust project is compiled, it will generate an executable independent binary program file or a general dynamic library file based on the project properties. These generated files need to be provided to other projects for use or integration. For ease of use, this solution framework uses the conan function module to upload it to the package management server. Users use and integrate it in the conan way, which simplifies the complexity of the dependency and version management process.
[0057] (3) Package management server:
[0058] The entire company level will generally build a package management server, which is used uniformly by all the subordinate departments and teams. The package management server is used for storage, uploading, downloading, querying, and other functions of binary program packages. It is suitable for using the conan system as the framework of the package management server.
[0059] (4) Parameter and compilation bridge module, also known as Cmake function module:
[0060] Rust has a complete compilation system cargo tool, which can realize the complete package management and compilation of Rust code. The Cmake system is directly introduced in this framework because the conan system does not support the cargo tool, so a bridge from the conan module to the cargo module is needed, and the Cmake function module is responsible for connecting the conan module to the cargo module.
[0061] The parameter and compilation bridge module in the framework is built based on the Cmake functional module. It is only responsible for calling cargo-related commands, organizing and aggregating the parameters required by cargo, and does not participate in the specific compilation process control. The Cmake functional module is used to implement the following functions:
[0062] 1) Gather multiple compilation parameters passed in by the upper-level conon module, including: all parameters passed in by build.sh, local path parameters that rely on third-party libraries, and project property setting parameters;
[0063] 2) Convert the compilation parameters into environment variables and pass them to the lower-level cargo function module so that it can correctly obtain these parameter information;
[0064] 3) Start the cargo function module and compile the Rust source code;
[0065] (5) Rust compilation management module, also known as cargo module:
[0066] The cargo module is the core of the entire system. It performs specific compilation work and controls the compilation process of the entire source code based on the passed parameters. The cargo module can achieve the following functions:
[0067] 1) Rust dependency and parameter configuration: mainly implemented by the cargo.toml configuration file;
[0068] 2) Platform version and compilation optimization parameters: mainly implemented by cargo / config;
[0069] 3) Rust-C++ calls each other to compile the Bridge module: mainly implemented by the build.rs file;
[0070] 4) Parameter setting: passed in through the cargo command line;
[0071] 5) lockfile configuration: The service depends on the lock of the third-party library version, which is implemented by the cargo.lock file.
[0072] (6) Rust / C++ mixed programming and compilation modules:
[0073] The project includes two parts of source code, C++ and Rust. In order to enable the Rust code to truly use the functions implemented in C++, the C++ code needs to be compiled into an ABI-compatible static library file, so that the Rust code can call the function code implemented in C++ through the standard FFI interface. The project organization, directory structure management, and compilation of the C++ code in the project are all implemented through Rust / C++ mixed programming and compilation modules.
[0074] The Rust / C++ mixed programming and compilation module contains the build.rs file, which completes the compilation of C++ code in the project, including the compilation of pure C++ code modules, Rust-C++ mutual call Bridge modules, and other source codes. Before compiling the Rust source code, the Rust compilation management module will first call the Rust / C++ mixed programming and compilation module to compile the C++ code into an application binary interface (ABI) compatible static library file, and then compile the Rust source code.
[0075] The build.rs file mainly calls the cc module to complete C++ code compilation.
[0076]
[0077]
[0078] (7) Gitlab code management server:
[0079] When compiling, the Rust compilation module needs to use the dependent library that the Rust source code depends on, that is, the Rust library, which is obtained from the Gitlab code management server.
[0080] In the above compilation method, the smart car software developed by integrating Rust and C++ can make the dependency and version management of the existing C++ basic library compatible with the dependency and version management of the new Rust library. In the same software project, although Rust and C++ each have a completely different compilation system, the unified compilation method provided by the above compilation method can be used to compile the codes of both, completely ignoring the difference between the two, and the upper-level users are transparent and unaware.
[0081] like Figure 3 As shown, the embodiment of the present application further provides a compiling device 300, the device comprising:
[0082] A first acquisition module 301 is used to acquire a first source code and a second source code in a project, wherein the first source code is written in a first programming language, and the second source code is written in a second programming language, the project is used to implement at least one software function, and the first programming language and the second programming language are incompatible;
[0083] A first compiling module 302, used to compile the first source code to obtain a static library;
[0084] The second compiling module 303 is used to compile the second source code according to the static library, the pre-acquired dependent library on which the second source code depends, and the pre-acquired environment variables to obtain a target code.
[0085] Optionally, the first compiling module 302 includes:
[0086] A first acquisition submodule, used to acquire a dependent library on which the first source code depends;
[0087] Add a submodule to add it to the dependency directory of the project;
[0088] The first compiling submodule is used to compile the first source code according to the dynamic library of the first source code in the dependent directory to obtain a static library.
[0089] Optionally, the first acquisition submodule includes:
[0090] A determination unit, configured to determine a dependent library on which the first source code depends according to a configuration file of the engineering project;
[0091] The downloading unit is used to download the dependent library on which the first source code depends from the package management server.
[0092] Optionally, the device further comprises:
[0093] The storage module is used to store the dynamic library composed of the target code in the package management server.
[0094] Optionally, the device further comprises:
[0095] A second acquisition module is used to acquire compilation parameters, wherein the compilation parameters include configuration parameters, local path parameters of a third-party library that the project depends on, and property setting parameters of the project, wherein the configuration parameters include at least one of a compilation type, a hardware platform, and a model of an adapted vehicle;
[0096] The third acquisition module is used to convert the compilation parameters to obtain the environment variables.
[0097] Optionally, the configuration parameters are configured by compiling a script.
[0098] The compiling device 300 provided in the embodiment of the present application can realize the aforementioned Figure 1 Each process implemented by the illustrated method embodiment can also achieve the same technical effect, and will not be described again here to avoid repetition.
[0099] like Figure 4As shown, the present application further provides a compiling device 400, the compiling device 400 comprising a processor 401, a memory 402 and a communication interface 403, the memory 402 storing programs or instructions that can be run on the processor 401,
[0100] Processor 401 is used to obtain a first source code and a second source code in an engineering project, the first source code is written in a first programming language, the second source code is written in a second programming language, the engineering project is used to implement at least one software function, and the first programming language and the second programming language are incompatible; compile the first source code to obtain a static library; compile the second source code according to the static library, a pre-acquired dependent library on which the second source code depends, and a pre-acquired environment variable to obtain a target code.
[0101] Optionally, the processor 401 is further used to obtain a dependent library on which the first source code depends, and add it to a dependent directory of the engineering project; and compile the first source code according to the dynamic library of the first source code in the dependent directory to obtain a static library.
[0102] Optionally, the processor 401 is further configured to determine, based on a configuration file of the engineering project, a dependent library on which the first source code depends; and download the dependent library on which the first source code depends from a package management server.
[0103] Optionally, the processor 401 is further configured to store the dynamic library composed of the target code in the package management server.
[0104] Optionally, processor 401 is also used to obtain compilation parameters, which include configuration parameters, local path parameters of a third-party library that the engineering project depends on, and property setting parameters of the engineering project, and the configuration parameters include at least one of the compilation type, hardware platform, and compatible vehicle model; convert the compilation parameters to obtain the environment variables.
[0105] Optionally, the configuration parameters are configured by compiling a script.
[0106] The program or instruction is implemented when the processor 401 executes it Figure 1 Each process implemented by the illustrated method embodiment can also achieve the same technical effect, and will not be described again here to avoid repetition.
[0107] The present application also provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the following is implemented: Figure 1 The steps of the compiling method in the illustrated embodiment.
[0108] The present application also provides a vehicle, the vehicle comprising a vehicle system, the vehicle system when executed to achieve Figure 1 Each process implemented by the illustrated method embodiment can also achieve the same technical effect, and will not be described again here to avoid repetition.
[0109] It should be understood that the above specific embodiments of the present invention are only used to illustrate or explain the principles of the present invention, and do not constitute a limitation of the present invention. Therefore, any modifications, equivalent substitutions, improvements, etc. made without departing from the spirit and scope of the present invention should be included in the protection scope of the present invention. In addition, the appended claims of the present invention are intended to cover all changes and modifications that fall within the scope and boundaries of the appended claims, or the equivalent forms of such scope and boundaries.
[0110] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprises" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0111] It should also be noted that the exemplary embodiments mentioned in the present invention describe some methods or systems based on a series of steps or devices. However, the present invention is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiments, or in a different order from the embodiments, or several steps can be performed simultaneously.
[0112] The above reference is according to the method of the embodiment of the present application, the flow chart of the device (system) and the computer program product and / or the block diagram described various aspects of the present application.It should be understood that each square box in the flow chart and / or the block diagram and the combination of each square box in the flow chart and / or the block diagram can be realized by computer program instructions.These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the realization of the function / action specified in one or more square boxes of the flow chart and / or the block diagram.Such a processor can be but is not limited to a general-purpose processor, a special-purpose processor, a special application processor or a field programmable logic circuit.It can also be understood that each square box in the block diagram and / or the flow chart and the combination of the square boxes in the block diagram and / or the flow chart can also be realized by the dedicated hardware that performs the specified function or action, or can be realized by the combination of dedicated hardware and computer instructions.
[0113] The above is only a specific implementation of the present invention. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the system, module and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. It should be understood that the protection scope of the present invention is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be covered within the protection scope of the present invention.
Claims
1. A compiling method, characterized in that: The method comprises: Obtaining a first source code and a second source code in a project, wherein the first source code is written in a first programming language, and the second source code is written in a second programming language, the project is used to implement at least one software function, and the first programming language and the second programming language are incompatible; Compiling the first source code to obtain a static library; The second source code is compiled according to the static library, the pre-acquired dependent library on which the second source code depends, and the pre-acquired environment variables to obtain a target code.
2. The method according to claim 1, characterized in that The step of compiling the first source code to obtain a static library includes: Obtaining a dependent library on which the first source code depends, and adding the library to a dependent directory of the engineering project; According to the dynamic library of the first source code in the dependent directory, the first source code is compiled to obtain a static library.
3. The method according to claim 2, characterized in that Obtaining the dependent library on which the first source code depends, including: Determining, according to a configuration file of the engineering project, a dependent library on which the first source code depends; Download the dependent library on which the first source code depends from the package management server.
4. The method according to claim 3, characterized in that After compiling the second source code according to the static library, the pre-acquired dependent library on which the second source code depends, and the pre-acquired environment variables to obtain the target code, the method further includes: The dynamic library composed of the object code is stored in the package management server.
5. The method according to claim 1, characterized in that The method further comprises: Obtaining compilation parameters, the compilation parameters including configuration parameters, local path parameters of a third-party library that the project depends on, and property setting parameters of the project, the configuration parameters including at least one of a compilation type, a hardware platform, and a model of an adapted vehicle; The compilation parameters are converted to obtain the environment variables.
6. The method according to claim 5, characterized in that The configuration parameters are configured by compiling a script.
7. A compiling device, characterized in that: The device comprises: An acquisition module, configured to acquire a first source code and a second source code in a project, wherein the first source code is written in a first programming language, and the second source code is written in a second programming language, and the project is configured to implement at least one software function; A first compiling module, used for compiling the first source code to obtain a static library; The second compiling module is used to compile the second source code according to the static library, the pre-acquired dependent library on which the second source code depends, and the pre-acquired environment variables to obtain the target code.
8. A compiling device, characterized in that: The device comprises a processor and a memory, wherein the memory stores a program or instruction that can be run on the processor, and when the program or instruction is executed by the processor, the steps of the compiling method according to any one of claims 1 to 6 are implemented.
9. A readable storage medium, characterized in that: The readable storage medium stores a program or an instruction, and when the program or the instruction is executed by a processor, the steps of the compiling method according to any one of claims 1 to 6 are implemented.
10. A vehicle, characterized in that: The vehicle includes a vehicle computer system, and the vehicle computer system, when executed, implements the steps of the compilation method according to any one of claims 1 to 6.
