Cross-platform compiling method and device, medium and equipment
By building the target container image on the current hardware platform and simulating the target architecture using an emulator and interpreter, the problem of low cross-platform development efficiency in existing technologies is solved, and efficient application development and compilation between different hardware architectures is achieved.
Patent Information
- Application Number
- CN202410303145.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-15
- Publication Date
- 2025-09-16
AI Technical Summary
Existing cross-platform development methods require compiling applications separately on each target platform, increasing development costs and reducing efficiency.
By obtaining the target emulator and interpreter, building the target container image, simulating the target architecture on the current hardware platform to compile the application, and using the emulator and interpreter to perform cross-platform development without owning the physical architecture hardware.
It improves the flexibility and convenience of the compilation process, enhances the efficiency and feasibility of cross-platform development, and reduces dependence on specific hardware.
Smart Images

Figure CN120653250A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a cross-platform compilation method, apparatus, medium, and device. Background Art
[0002] The rapid development of information technology and the widespread adoption of diverse hardware platforms and operating systems have brought new challenges to software development. Developers need to ensure that their applications can run on a variety of hardware architectures, including but not limited to x86, ARM, MIPS, and Alpha. This demand has spurred the development of cross-platform development tools and technologies. However, existing cross-platform development methods typically involve compiling the application separately for each target platform, which not only increases development costs but also reduces efficiency. Summary of the Invention
[0003] The embodiments of the present application provide a cross-platform compilation method, apparatus, medium, and device that can compile applications without physical hardware, thereby improving the flexibility and convenience of the compilation process and enhancing the efficiency and feasibility of cross-platform development. The above technical solutions are as follows:
[0004] In a first aspect, an embodiment of the present application provides a cross-platform compilation method, the method comprising:
[0005] Get the corresponding target simulator according to the current hardware platform and target architecture;
[0006] Register the target interpreter corresponding to the above target architecture in the above current hardware platform;
[0007] Add the above target emulator to the base container image to build the target container image;
[0008] Run the target container image on the current hardware platform to compile the target application.
[0009] In one possible implementation, the step of obtaining a corresponding target simulator based on the current hardware platform and the target architecture includes:
[0010] Get the hardware architecture corresponding to the current hardware platform;
[0011] Determine the target architecture based on the compilation architecture corresponding to the target application;
[0012] Determine whether the target architecture is consistent with the hardware architecture;
[0013] If they are inconsistent, the corresponding target simulator is obtained according to the above hardware architecture and the above target architecture.
[0014] In one possible implementation, registering the target interpreter corresponding to the target architecture in the current hardware platform includes:
[0015] Get the interpreter registered in the current hardware platform;
[0016] Determine whether there is a target interpreter corresponding to the target architecture among the registered interpreters;
[0017] If it does not exist, register the target interpreter in the current hardware platform.
[0018] In one possible implementation, adding the target emulator to the base container image to build the target container image includes:
[0019] Determine the corresponding base container image based on the target emulator;
[0020] Add the target emulator to the specified directory of the base container image.
[0021] Set the environment variables and dependencies corresponding to the target application in the above base container image to build the target container image.
[0022] In a possible implementation, after adding the target emulator to the base container image to build the target container image, the method further includes:
[0023] The target container image is uploaded to a cloud server, where the cloud server includes one or more target container images corresponding to different target emulators.
[0024] In one possible implementation, running the target container image on the current hardware platform to compile the target application includes:
[0025] Get the hardware architecture corresponding to the current hardware platform and the compilation architecture corresponding to the target application;
[0026] Obtain a matching target container image from the cloud server based on the hardware architecture and the compilation architecture.
[0027] Run the matching target container image on the current hardware platform to compile the target application.
[0028] In a possible implementation, the target emulator is a QEMU emulator, and the base container image is a Docker container image.
[0029] In a second aspect, an embodiment of the present application provides a cross-platform compilation device, which includes:
[0030] The acquisition module is used to obtain the corresponding target simulator according to the current hardware platform and target architecture;
[0031] A registration module, used to register the target interpreter corresponding to the target architecture in the current hardware platform;
[0032] A construction module, used to add the above target emulator to the base container image to build the target container image;
[0033] The running module is used to run the above target container image on the above current hardware platform to compile the target application.
[0034] In a possible implementation, the acquisition module is specifically configured to:
[0035] Get the hardware architecture corresponding to the current hardware platform;
[0036] Determine the target architecture based on the compilation architecture corresponding to the target application;
[0037] Determine whether the target architecture is consistent with the hardware architecture;
[0038] If they are inconsistent, the corresponding target simulator is obtained according to the above hardware architecture and the above target architecture.
[0039] In one possible implementation, the registration module is specifically configured to:
[0040] Get the interpreter registered in the current hardware platform;
[0041] Determine whether there is a target interpreter corresponding to the target architecture among the registered interpreters;
[0042] If it does not exist, register the target interpreter in the current hardware platform.
[0043] In one possible implementation, the above building blocks are specifically used to:
[0044] Determine the corresponding base container image based on the target emulator;
[0045] Add the target emulator to the specified directory of the base container image.
[0046] Set the environment variables and dependencies corresponding to the target application in the above base container image to build the target container image.
[0047] In a possible implementation, the device further includes an upload module, which is specifically configured to:
[0048] The target container image is uploaded to a cloud server, where the cloud server includes one or more target container images corresponding to different target emulators.
[0049] In a possible implementation, the operation module is specifically configured to:
[0050] Get the hardware architecture corresponding to the current hardware platform and the compilation architecture corresponding to the target application;
[0051] Obtain a matching target container image from the cloud server based on the hardware architecture and the compilation architecture.
[0052] Run the matching target container image on the current hardware platform to compile the target application.
[0053] In a possible implementation, the target emulator is a QEMU emulator, and the base container image is a Docker container image.
[0054] In a third aspect, an embodiment of the present application provides a computer storage medium, which stores instructions, and the instructions are suitable for being loaded by a processor and executing the method provided by the first aspect of the embodiment of the present application or any possible implementation of the first aspect.
[0055] In a fourth aspect, an embodiment of the present application provides an electronic device, including: a processor and a memory;
[0056] The processor is connected to the memory;
[0057] The aforementioned memory is used to store executable program code;
[0058] The processor runs the program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method provided by the first aspect of the embodiment of the present application or any possible implementation of the first aspect.
[0059] In one or more embodiments of the present application, a corresponding target emulator is obtained according to the current hardware platform and the target architecture; a target interpreter corresponding to the target architecture is registered in the above-mentioned current hardware platform; the above-mentioned target emulator is added to the base container image to build a target container image; and the above-mentioned target container image is run on the above-mentioned current hardware platform to compile the target application. This method can effectively support and simplify the application development and compilation process between different hardware architectures. By using the emulator and the corresponding interpreter, developers are allowed to simulate another target architecture on one hardware platform, thereby developing, testing and compiling applications without owning the physical architecture hardware. Integrating the emulator into the base container image and building the target container image further improves the flexibility and convenience of the compilation process, allowing developers to reuse these images on the same or different hardware platforms, thereby significantly improving the efficiency and feasibility of cross-platform development. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0061] Figure 1 A schematic diagram of the architecture of a cross-platform compilation system provided by an exemplary embodiment of the present application;
[0062] Figure 2 A flowchart of a cross-platform compilation method provided by an exemplary embodiment of the present application;
[0063] Figure 3 A flowchart of a cross-platform compilation method provided by an exemplary embodiment of the present application;
[0064] Figure 4 A flowchart of a method for building a target container image provided by an exemplary embodiment of the present application;
[0065] Figure 5 A flowchart of a cross-platform compilation method provided by an exemplary embodiment of the present application;
[0066] Figure 6 A schematic structural diagram of a cross-platform compilation device provided as an exemplary embodiment of the present application;
[0067] Figure 7 A schematic structural diagram of an electronic device provided as an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0068] When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are merely examples of devices and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0069] In the description of this application, it should be understood that the terms "first", "second", etc. are used for descriptive purposes only and should not be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in this application can be understood according to specific circumstances. In addition, in the description of this application, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship.
[0070] The present application is described in detail below with reference to specific embodiments.
[0071] Please refer to Figure 1 , Figure 1 This is a schematic diagram of the architecture of a cross-platform compilation system provided by an exemplary embodiment of the present application. Figure 1 As shown, the cross-platform compilation system may include a terminal 110 and a server 120 .
[0072] Terminal 110 is connected to server 120 via network 130. Optionally, terminal 110 may be a laptop, desktop computer, smartphone, tablet computer, smartwatch, etc., but is not limited thereto. Terminal 110 may install and run applications that support cross-platform compilation. Network 130 may be a wireless network or a wired network.
[0073] Server 120 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, a Content Delivery Network (CDN), and big data and artificial intelligence platforms. Server 120 may provide background services for applications running on terminal 110 that support cross-platform compilation, such as providing an emulator download service.
[0074] Those skilled in the art will appreciate that the number of terminals 110 and servers 120 can be greater or lesser. For example, there may be only one terminal 110 and server 120, or there may be dozens, hundreds, or even more terminals 110 and servers 120, in which case the system architecture may also include other terminals and servers. Furthermore, in some embodiments, only one terminal 110 or server 120 may be deployed. The embodiments of this application do not limit the number of terminals or device types.
[0075] The cross-platform compilation method involved in one or more embodiments of the present application can be implemented by a computer program and can be run on a cross-platform compilation device based on the von Neumann architecture. The computer program can be integrated into an application or run as an independent tool application. The execution entity corresponding to the cross-platform compilation method can be the terminal 110 described above or the server 120. The specific implementation is determined based on the actual application environment and is not limited in the embodiments of the present application.
[0076] Next, combine Figure 1 , introduces the cross-platform compilation method provided by the embodiment of this application. For details, please refer to Figure 2 , which is a flow chart of a cross-platform compilation method provided by an exemplary embodiment of the present application, with the terminal as the execution subject, such as Figure 2 As shown, the cross-platform compilation method includes the following steps:
[0077] S201, obtaining a corresponding target simulator according to the current hardware platform and target architecture.
[0078] Specifically, the current hardware platform refers to the physical machine that runs the operating system and application programs. Its CPU (Central Processing Unit) architecture may include various CPU architectures, such as x86_64 (or AMD64), i386 (or x86), ARMv7 (32-bit), ARMv8 (64-bit, also known as ARM64 or aarch64), PowerPC, MIPS, and RISC-V. The target architecture is the specified CPU architecture or the CPU architecture corresponding to the application that needs to run across platforms. Application programs generally need to be compiled and run on hardware with the corresponding CPU architecture. For example, an application designed using the x86 architecture can run directly on hardware with the x86 architecture, but cannot run directly on hardware with the ARM64 architecture.
[0079] An emulator is a software or hardware that can simulate (emulate) the operation of another CPU architecture, allowing a program designed for another CPU architecture (target architecture) to run on one CPU architecture (host architecture or hardware architecture). Emulators may include but are not limited to QEMU emulators, Bochs emulators, SkyEye emulators, Unicorn Engine emulators, etc. The target emulator in this embodiment is an emulator that allows the target architecture to be simulated on the current hardware platform.
[0080] In some embodiments, the above-mentioned obtaining the corresponding target emulator based on the current hardware platform and the target architecture includes: obtaining the hardware architecture corresponding to the current hardware platform; determining the target architecture based on the compilation architecture corresponding to the target application; determining whether the target architecture is consistent with the hardware architecture; if not, obtaining the corresponding target emulator based on the hardware architecture and the target architecture.
[0081] Specifically, in the automation process, before the terminal compiles the target application, it needs to prepare the corresponding operating environment, can detect and identify the current hardware platform to determine the corresponding CPU architecture (hardware architecture), can detect and identify the target application to determine the corresponding CPU architecture (compilation architecture), and use the compilation architecture as the target architecture. When the target architecture is consistent with the hardware architecture, it means that the CPU architecture of the target application is the same as the CPU architecture of the current hardware platform, and the target application can be compiled directly on the current hardware platform. When the target architecture is inconsistent with the hardware architecture, it means that the CPU architecture of the target application is different from the CPU architecture of the current hardware platform, and the target application cannot be compiled directly on the current hardware platform, and a corresponding cross-platform compilation method needs to be adopted, that is, it needs to execute the steps of obtaining the corresponding target emulator according to the hardware architecture and the target architecture. Through the above method, the automation process can automatically determine whether a cross-platform compilation method needs to be adopted for the application to be compiled, which can improve the development efficiency of developers.
[0082] In this embodiment, the target simulator can be obtained according to the hardware architecture and the target architecture. For example, if the hardware architecture is x86_64 and the target architecture is ARM64, the target simulator is a simulator that simulates the ARM64 architecture on the x86_64 architecture; for example, if the hardware architecture is ARM64 and the target architecture is MIPS, the target simulator is a simulator that simulates the MIPS architecture on the ARM64 architecture. In some embodiments, the same target simulator can also have different versions. When obtaining the target simulator, a default version can be selected or a certain version can be manually specified, and the adapted version can be determined according to performance requirements. After determining the target simulator, the corresponding version of the target simulator can be downloaded to the terminal from the official website, third-party website, cloud server or local storage.
[0083] S202, registering a target interpreter corresponding to the target architecture in the current hardware platform.
[0084] Specifically, an interpreter refers to a program that can recognize and execute non-native binary formats. For example, when an ARM architecture binary file runs on an x86 architecture machine, a special interpreter is required to "translate" ARM instructions into x86 instructions. This translation or simulation process can be completed by an emulator. A target interpreter refers to a program that can run binary files of the target architecture on the current hardware platform. Registering an interpreter is to configure a mechanism in the current hardware platform to register the interpreter by writing rules. These rules define how to identify files of a specific format and which interpreter to use to execute these files. After the rules are written, when the system tries to execute files that match these rules, the kernel will automatically call the specified interpreter to execute these files, thereby automatically identifying and using specific interpreter programs to execute binary files of non-native architectures.
[0085] For example, if you want to automatically use the QEMU emulator to execute ARM architecture binary files on an x86_64 architecture system, you need to register a properly configured QEMU ARM interpreter as a handler for ARM architecture binary files.
[0086] In some embodiments, the above-mentioned registration of the target interpreter corresponding to the target architecture in the current hardware platform includes: obtaining the interpreters registered in the current hardware platform; determining whether there is a target interpreter corresponding to the target architecture in the registered interpreters; if not, registering the target interpreter in the current hardware platform.
[0087] Specifically, the current hardware platform system can register multiple interpreters, and each registered interpreter has a corresponding file. The file name can be set to be related to the interpreter or the supported architecture and stored in the system-specified directory. The list of interpreters registered in the current hardware platform system can be obtained by querying the system-specified directory. Determine whether there is already a target interpreter registered for the target architecture based on the interpreter file name. For example, if the target architecture is ARM64, it is necessary to find the registration entry related to qemu-aarch64. If the target interpreter does not exist, it means that the current hardware platform has not registered a target interpreter that supports the target architecture, and the target interpreter needs to be registered so that the current hardware platform system can automatically recognize and execute binary files of the target architecture. Through the above method, by effectively managing the registration of interpreters, it can be ensured that the system can automatically recognize and execute binary files of non-native architectures, which greatly improves work efficiency.
[0088] S203: Add the target emulator to the base container image to build the target container image.
[0089] Specifically, a base container image is the starting point for building a container. It contains the most basic environment necessary to run an application, such as core operating system components and runtime libraries. A base container image may not contain the application itself, but provides an environment that enables the application to run on it. For example, base container images might be ubuntu, alpine, or debian, which provide the basic operating environments of Ubuntu, Alpine Linux, and Debian, respectively.
[0090] A target container image is a container image that already includes all necessary dependencies (including a target emulator, such as QEMU). It is designed to provide all necessary components and a container environment for running target architecture applications on non-target hardware platforms to ensure that the applications can run correctly in a containerized environment.
[0091] In this embodiment, the optional container technology may be Docker, Podman, containerd, etc.
[0092] In some embodiments, the above-mentioned adding the target emulator to the base container image to build the target container image includes: determining the corresponding base container image according to the target emulator; adding the target emulator to a specified directory of the base container image; setting the environment variables and dependent programs corresponding to the target application in the base container image to build the target container image.
[0093] Specifically, determine the base container image based on the target emulator. The base container image can provide the environment and libraries for the target architecture to run, and at the same time have high compatibility with the target emulator so that it can run correctly in the simulation environment. For example, if the target architecture is the ARM64 architecture and QEMU is used to simulate the ARM64 architecture, a base image suitable for ARM64 should be selected, such as arm64v8 / ubuntu. Then, add the target emulator to the specified directory of the base container image, so that the environment in the container can support running applications of the target architecture, even on non-target hardware. Finally, configure the container image to meet the running requirements of the target application, including installing the required dependent programs, libraries, and setting environment variables, etc., to ensure that the container image not only contains the emulator required to run the target architecture application, but also configures all necessary runtime environments and dependencies so that the target application can run correctly in the container.
[0094] S204: Run the target container image on the current hardware platform to compile the target application.
[0095] Specifically, after the target container image is built, it can be run on the current hardware platform to start a container instance. The internal environment of the container is configured to simulate the target architecture, allowing the compilation and testing process of the target application to be executed in it. The compilation and testing process is the same as running on hardware with the same target architecture.
[0096] In an embodiment of the present application, a corresponding target emulator is obtained based on the current hardware platform and target architecture; a target interpreter corresponding to the target architecture is registered in the current hardware platform; the target emulator is added to a base container image to construct a target container image; and the target container image is run on the current hardware platform to compile a target application. This method utilizes containerization technology and architecture emulators to compile and test applications for different target architectures in a unified development environment, improving the accessibility and efficiency of cross-platform development, reducing dependence on specific hardware, and increasing the flexibility and automation of the development process.
[0097] The following describes the cross-platform compilation method in conjunction with a specific implementation scenario. In this exemplary embodiment, the target emulator uses the QEMU emulator, the base container image is a Docker container image (i.e., the base image follows the Docker image format), the current hardware platform uses the x86 architecture as an example, and the target architecture uses the ARM64 architecture as an example. Figure 3 , which is a flow chart of a cross-platform compilation method provided by an exemplary embodiment of the present application. Figure 3 As shown, the cross-platform compilation method includes the following steps:
[0098] S301, obtain the corresponding QEMU emulator according to the x86 hardware platform and ARM64 architecture.
[0099] Specifically, according to the x86 hardware platform and ARM64 architecture, you can download the corresponding QEMU emulator, such as qemu-aarch64-static. This executable file can simulate the ARM64 CPU architecture instruction set in the x86 environment.
[0100] S302, register the QEMU interpreter corresponding to the ARM64 architecture in the x86 hardware platform.
[0101] Specifically, you can run a temporary container (such as a Docker image) and register the QEMU user mode binary file as the interpreter through the temporary container. Directly registering the QEMU interpreter may require downloading the appropriate version of the QEMU user mode binary file and then manually configuring the system (for example, by modifying the files under / proc / sys / fs / binfmt_misc / ) to recognize and execute programs for non-native architectures. Using a Docker image can automate this process, simplifying the installation and configuration steps.
[0102] S303, adding the QEMU emulator to the base Docker image to build the target Docker image.
[0103] Specifically, add the QEMU emulator qemu-aarch64-static to the selected base Docker image to build the target Docker image. The target Docker image contains the necessary QEMU emulator to emulate the ARM64 architecture on the x86 hardware platform. Building the target Docker image can be achieved by writing a Dockerfile.
[0104] For example, in the Dockerfile, a base Docker image is specified according to the ARM64 architecture, such as ubuntu:18.04, which means that the target Docker image built will be based on the Ubuntu 18.04LTS version. The qemu-aarch64-static file is copied from the host machine to the / usr / bin directory of the Docker container, which enables the Docker container to emulate ARM64 architecture applications on the x86 architecture host machine. The environment variable PATH is set to include the binary file path of Miniconda3 to ensure that the command line environment in the Docker container can directly access the tools and scripts provided by Miniconda3. The package list is updated and a series of build and network tools are installed using apt-get, such as wget, autoconf, automake, libtool, etc. These tools can be used to compile and install software. Then, the apt cache is cleaned to reduce the image size. In some embodiments, it is also necessary to add the installation command of Miniconda3 to ensure that the command line environment in the Docker container can correctly access the tools and scripts provided by Miniconda3. Finally, the Docker image is compiled through docker build to generate the target Docker image for the ARM64 architecture.
[0105] S304: Run the target Docker image to generate an executable program to compile an application for the ARM64 architecture.
[0106] Specifically, after the target Docker image is built, it can be run on the x86 hardware platform to start a container instance. The internal environment of the container is configured to simulate the ARM64 architecture, allowing the compilation and testing process of ARM64 architecture applications to be executed in it. The compilation and testing process is the same as running on hardware with the same ARM64 architecture.
[0107] See Figure 4 , which is a flowchart of the target container image building process provided by an exemplary embodiment of the present application. Figure 4 As shown, the method for building the target container image includes the following steps:
[0108] S401, obtaining a corresponding target simulator according to the current hardware platform and target architecture.
[0109] Specifically, step S401 is the same as step S201 and will not be described again here.
[0110] S402, registering a target interpreter corresponding to the target architecture in the current hardware platform.
[0111] Specifically, step S402 is the same as step S202 and will not be described again here.
[0112] S403: Add the target emulator to the base container image to build the target container image.
[0113] Specifically, step S403 is the same as step S203 and will not be described again here.
[0114] S404: Upload the target container image to the cloud server.
[0115] Specifically, the constructed target container image is uploaded to the cloud server, and then the process can return to step S401 and loop through steps S401-S404 to upload target container images constructed according to different target architectures, so that the cloud server can store target container images corresponding to multiple different target emulators.
[0116] For example, when the current hardware platform is x86, the target architecture can be set to ARM64, and an ARM64 architecture emulator can be obtained to simulate the ARM64 CPU architecture instruction set in an x86 environment. The ARM64 architecture interpreter is registered on the current hardware platform, and the ARM64 architecture emulator is used to build an ARM64 architecture target container image. After the ARM64 architecture target container image is uploaded to the cloud server, in addition to the current terminal being able to reuse the ARM64 architecture target container image, other terminals with the same architecture can also reuse the ARM64 architecture target container image through the cloud server.
[0117] Then, the target architecture is changed to MIPS. A MIPS emulator is obtained to simulate the MIPS CPU architecture instruction set in an x86 environment. The MIPS architecture interpreter is registered on the current hardware platform, and the MIPS architecture emulator is used to build a MIPS architecture target container image. After the MIPS architecture target container image is uploaded to the cloud server, it can be reused not only by the current terminal but also by other terminals with the same architecture through the cloud server.
[0118] In this way, the cloud server stores multiple target container images corresponding to different hardware platforms and different target architectures. The terminal can match the corresponding target container image according to the hardware architecture of the current hardware platform and the compilation architecture of the target application to achieve cross-platform compilation of the target application.
[0119] See Figure 5 , which is a flow chart of a cross-platform compilation method provided by an exemplary embodiment of the present application. Figure 5 As shown, the cross-platform compilation method includes the following steps:
[0120] S501, obtaining a hardware architecture corresponding to a current hardware platform and a compilation architecture corresponding to a target application.
[0121] Specifically, the current hardware platform can be detected and identified to determine the corresponding hardware architecture, and the target application can be detected and identified to determine the corresponding compilation architecture. When the compilation architecture and the hardware architecture are consistent, the target application can be directly compiled and run on the current hardware platform. If the compilation architecture and the hardware architecture are inconsistent, a corresponding cross-platform compilation method must be adopted and step S502 is executed.
[0122] S502: Obtain a matching target container image from a cloud server based on the hardware architecture and the compilation architecture.
[0123] Specifically, when the compilation architecture is inconsistent with the hardware architecture, in order to compile the target application on the current hardware platform, it is necessary to obtain the corresponding target container image in order to generate a container instance that can simulate the compilation architecture of the target application on the current hardware platform, allowing the target application to execute the compilation and testing process in the container. Since the cloud server pre-stores various target container images, they can be downloaded and used directly to avoid repeated construction, thereby improving development efficiency. If the target container image is not matched in the cloud server, the above steps S401-S404 can be executed to rebuild the corresponding target container image and upload it to the cloud server.
[0124] S503: Run the matching target container image on the current hardware platform to compile the target application.
[0125] Specifically, after obtaining the target container image that matches the target application, it can be run on the current hardware platform to generate a container instance and perform the compilation operation of the target application.
[0126] It should be noted that in order for the current hardware platform to be able to execute binary files of non-native architectures, in addition to manually registering the interpreter, the target container image can also automatically register the required interpreter on the host machine, enabling the host machine to run binary files of the required architecture.
[0127] Please refer to the following Figure 6 , Figure 6 A cross-platform compilation device is provided as an exemplary embodiment of the present application. Figure 6 As shown, the cross-platform compilation device 600 includes:
[0128] An acquisition module 610 is configured to acquire a corresponding target simulator based on the current hardware platform and target architecture;
[0129] A registration module 620 is used to register the target interpreter corresponding to the target architecture in the current hardware platform;
[0130] A construction module 630 is configured to add the target emulator to the base container image to construct a target container image;
[0131] The running module 640 is used to run the target container image on the current hardware platform to compile the target application.
[0132] In some possible embodiments, the acquisition module 610 is specifically configured to:
[0133] Get the hardware architecture corresponding to the current hardware platform;
[0134] Determine the target architecture based on the compilation architecture corresponding to the target application;
[0135] Determine whether the target architecture is consistent with the hardware architecture;
[0136] If they are inconsistent, the corresponding target simulator is obtained according to the above hardware architecture and the above target architecture.
[0137] In some possible embodiments, the registration module 620 is specifically configured to:
[0138] Get the interpreter registered in the current hardware platform;
[0139] Determine whether there is a target interpreter corresponding to the target architecture among the registered interpreters;
[0140] If it does not exist, register the target interpreter in the current hardware platform.
[0141] In some possible embodiments, the building module 630 is specifically configured to:
[0142] Determine the corresponding base container image based on the target emulator;
[0143] Add the target emulator to the specified directory of the base container image.
[0144] Set the environment variables and dependencies corresponding to the target application in the above base container image to build the target container image.
[0145] In some possible embodiments, the apparatus 600 further includes an upload module, and the upload module is specifically configured to:
[0146] The target container image is uploaded to a cloud server, where the cloud server includes one or more target container images corresponding to different target emulators.
[0147] In some possible embodiments, the operation module 640 is specifically configured to:
[0148] Get the hardware architecture corresponding to the current hardware platform and the compilation architecture corresponding to the target application;
[0149] Obtain a matching target container image from the cloud server based on the hardware architecture and the compilation architecture.
[0150] Run the matching target container image on the current hardware platform to compile the target application.
[0151] In some possible embodiments, the target emulator is a QEMU emulator, and the base container image is a Docker container image.
[0152] The division of the modules in the above-mentioned cross-platform compilation device is for illustration only. In other embodiments, the cross-platform compilation device can be divided into different modules as needed to complete all or part of the functions of the above-mentioned cross-platform compilation device. The implementation of each module in the cross-platform compilation device provided in the embodiments of the present application can be in the form of a computer program. The computer program can be run on a terminal or a server. The program modules constituted by the computer program can be stored in the memory of the terminal or the server. When the computer program is executed by the processor, all or part of the steps of the cross-platform compilation method described in the embodiments of the present application are implemented.
[0153] See also Figure 7 , Figure 7 This is a schematic diagram of the structure of an electronic device provided by an exemplary embodiment of the present application. Figure 7 As shown, the electronic device 700 may include: at least one processor 710, at least one communication bus 720, a user interface 730, at least one network interface 740, and a memory 750. The communication bus 720 may be used to implement connection and communication between the above components.
[0154] The user interface 730 may include a display screen (Display) and a camera (Camera), and the optional user interface may also include a standard wired interface and a wireless interface.
[0155] The network interface 740 may optionally include a Bluetooth module, a Near Field Communication (NFC) module, a Wireless Fidelity (Wi-Fi) module, and the like.
[0156] The processor 710 may include one or more processing cores. The processor 710 utilizes various interfaces and circuits to connect the various components within the electronic device 700. By running or executing instructions, programs, code sets, or instruction sets stored in the memory 750, and accessing data stored in the memory 750, the processor 710 performs various functions and processes data for the routing electronic device 700. Optionally, the processor 710 may be implemented using at least one of the following hardware forms: a digital signal processing (DSP), a field-programmable gate array (FPGA), or a programmable logic array (PLA). The processor 710 may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing the content displayed on the display; and the modem handles wireless communications. It is understood that the modem may not be integrated into the processor 710 and may be implemented as a separate chip.
[0157] Among them, the memory 750 may include a random access memory (RAM) or a read-only memory (ROM). Optionally, the memory 750 includes a non-transitory computer-readable medium. The memory 750 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 750 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as an acquisition function, a registration function, a construction function, an operation function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 750 may also be optionally at least one storage device located away from the aforementioned processor 710. As Figure 7 As shown, the memory 750 as a computer storage medium may include an operating system, a network communication module, a user interface module, and program instructions.
[0158] Specifically, the processor 710 may be configured to call program instructions stored in the memory 750 and perform the following operations:
[0159] Get the corresponding target simulator according to the current hardware platform and target architecture;
[0160] Register the target interpreter corresponding to the above target architecture in the above current hardware platform;
[0161] Add the above target emulator to the base container image to build the target container image;
[0162] Run the target container image on the current hardware platform to compile the target application.
[0163] In some possible embodiments, when the processor 710 executes the above-mentioned acquisition of the corresponding target simulator according to the current hardware platform and the target architecture, it further specifically executes:
[0164] Get the hardware architecture corresponding to the current hardware platform;
[0165] Determine the target architecture based on the compilation architecture corresponding to the target application;
[0166] Determine whether the target architecture is consistent with the hardware architecture;
[0167] If they are inconsistent, the corresponding target simulator is obtained according to the above hardware architecture and the above target architecture.
[0168] In some possible embodiments, when executing the above-mentioned registration of the target interpreter corresponding to the above-mentioned target architecture in the above-mentioned current hardware platform, the processor 710 further specifically executes:
[0169] Get the interpreter registered in the current hardware platform;
[0170] Determine whether there is a target interpreter corresponding to the target architecture among the registered interpreters;
[0171] If it does not exist, register the target interpreter in the current hardware platform.
[0172] In some possible embodiments, when executing the above-mentioned adding the target emulator to the base container image to build the target container image, the processor 710 further specifically executes:
[0173] Determine the corresponding base container image based on the target emulator;
[0174] Add the target emulator to the specified directory of the base container image.
[0175] Set the environment variables and dependencies corresponding to the target application in the above base container image to build the target container image.
[0176] In some possible embodiments, after executing the above-mentioned adding the target emulator to the base container image to build the target container image, the processor 710 further specifically executes:
[0177] The target container image is uploaded to a cloud server, where the cloud server includes one or more target container images corresponding to different target emulators.
[0178] In some possible embodiments, when executing the target container image on the current hardware platform to compile the target application, the processor 710 further specifically executes:
[0179] Get the hardware architecture corresponding to the current hardware platform and the compilation architecture corresponding to the target application;
[0180] Obtain a matching target container image from the cloud server based on the hardware architecture and the compilation architecture.
[0181] Run the matching target container image on the current hardware platform to compile the target application.
[0182] In some possible embodiments, the target emulator is a QEMU emulator, and the base container image is a Docker container image.
[0183] The present application also provides a computer-readable storage medium containing instructions that, when executed on a computer or processor, cause the computer or processor to perform one or more steps of the above-described embodiments. If the various components of the cross-platform compilation device are implemented as software functional units and sold or used as independent products, they can be stored in the computer-readable storage medium.
[0184] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The above-mentioned computer program product includes one or more computer instructions. When the above-mentioned computer program instructions are loaded and executed on a computer, the above-mentioned process or function according to the embodiment of the present application is generated in whole or in part. The above-mentioned computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable devices. The above-mentioned computer instructions can be stored in a computer-readable storage medium or transmitted by the above-mentioned computer-readable storage medium. The above-mentioned computer instructions can be transmitted from a website, computer, server or data center to another website, computer, server or data center by wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) mode. The above-mentioned computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The above-mentioned available media can be magnetic media (for example, floppy disks, hard disks, tapes), optical media (for example, digital versatile discs (DVDs)), or semiconductor media (for example, solid state disks (SSDs)).
[0185] Those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing the relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When executed, the program can include the processes of the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks. The technical features of this embodiment and the implementation scheme can be combined in any manner unless they conflict.
[0186] The embodiments described above are merely preferred embodiments of the present application and are not intended to limit the scope of the present application. Without departing from the design spirit of the present application, various modifications and improvements made to the technical solutions of the present application by ordinary technicians in this field should fall within the scope of protection determined by the claims.
[0187] The foregoing description describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims and the specification can be performed in a different order than that described in the embodiments described in the specification and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
Claims
1. A cross-platform compilation method, characterized in that: The method comprises: Get the corresponding target simulator according to the current hardware platform and target architecture; Registering a target interpreter corresponding to the target architecture in the current hardware platform; Add the target emulator to the base container image to build the target container image; The target container image is run on the current hardware platform to compile a target application.
2. The method according to claim 1, characterized in that The step of obtaining a corresponding target simulator according to the current hardware platform and the target architecture includes: Get the hardware architecture corresponding to the current hardware platform; Determine the target architecture based on the compilation architecture corresponding to the target application; Determining whether the target architecture is consistent with the hardware architecture; If they are inconsistent, a corresponding target simulator is obtained according to the hardware architecture and the target architecture.
3. The method according to claim 1, characterized in that The registering the target interpreter corresponding to the target architecture in the current hardware platform includes: Obtain the interpreter registered in the current hardware platform; Determine whether there is a target interpreter corresponding to the target architecture in the registered interpreters; If not, register the target interpreter in the current hardware platform.
4. The method according to claim 1, wherein Adding the target emulator to the base container image to build the target container image includes: Determine the corresponding base container image based on the target emulator; Add the target emulator to the specified directory of the base container image; The environment variables and dependent programs corresponding to the target application are set in the base container image to build the target container image.
5. The method according to claim 1, wherein After adding the target emulator to the base container image to build the target container image, the method further includes: The target container image is uploaded to a cloud server, where the cloud server includes one or more target container images corresponding to different target emulators.
6. The method according to claim 5, characterized in that Running the target container image on the current hardware platform to compile a target application includes: Get the hardware architecture corresponding to the current hardware platform and the compilation architecture corresponding to the target application; Obtaining a matching target container image in the cloud server according to the hardware architecture and the compilation architecture; The matching target container image is run on the current hardware platform to compile the target application.
7. The method according to any one of claims 1 to 6, characterized in that The target emulator is a QEMU emulator, and the base container image is a Docker container image.
8. A cross-platform compilation device, characterized in that: The device comprises: The acquisition module is used to obtain the corresponding target simulator according to the current hardware platform and target architecture; A registration module, configured to register a target interpreter corresponding to the target architecture in the current hardware platform; A construction module, configured to add the target emulator to a base container image to construct a target container image; A running module is used to run the target container image on the current hardware platform to compile a target application.
9. A computer storage medium, characterized in that The computer storage medium stores instructions, which are suitable for being loaded by a processor and executing the method steps according to any one of claims 1 to 7.
10. An electronic device, characterized in that: include: processor and memory; The processor is connected to the memory; The memory is used to store executable program code; The processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method steps according to any one of claims 1 to 7.