{"id":34008,"date":"2024-06-12T10:01:40","date_gmt":"2024-06-12T02:01:40","guid":{"rendered":"https:\/\/www.deepin.org\/?p=34008"},"modified":"2024-11-06T15:30:22","modified_gmt":"2024-11-06T07:30:22","slug":"building-linglong-format-applications-from-source-code","status":"publish","type":"post","link":"https:\/\/www.deepin.org.cn\/en\/building-linglong-format-applications-from-source-code\/","title":{"rendered":"[PM Direct] Building Linglong Format Applications from Source Code"},"content":{"rendered":"<img loading=\"lazy\" src=\"https:\/\/storage.deepin.org\/thread\/202406120206363038_3-en.jpg\" alt=\"\" width=\"900\" height=\"383\" \/><\/p>\n<p>Please first read <a href=\"https:\/\/linglong.dev\/guide\/ll-builder\/introduction.html\">the official Linglong documentation.<\/a> This article uses the construction of <a href=\"https:\/\/github.com\/zty199\/desktop-entry-editor\">desktop-entry-editor<\/a> as an example. The project has relatively simple dependencies and only requires the basic runtime environment provided by default in the official Linglong documentation to be successfully built and run.<\/p>\n<h1 id=\"\u7b2c\u4e00\u6b65-\u524d\u671f\u51c6\u5907\" style=\"text-align: center;\"><strong>Step One: Preliminary Preparations<\/strong><\/h1>\n<p>Execute the following command in the terminal:<\/p>\n<blockquote><p><code class=\"hljs solidity\">sudo apt install linglong<span class=\"hljs-operator\">-<\/span>builder <span class=\"hljs-operator\">-<\/span><span class=\"hljs-operator\">-<\/span>no<span class=\"hljs-operator\">-<\/span>install<span class=\"hljs-operator\">-<\/span>recommends<\/code><\/p><\/blockquote>\n<p>Install the <code>ll-builder<\/code> tool.<\/p>\n<p><img class=\"aligncenter\" src=\"https:\/\/storage.deepin.org\/thread\/20240605121436813_1.png\" alt=\"1.png\" \/><\/p>\n<blockquote><p>Since the recommended installation has many dependencies, they are skipped in this instance. If needed, simply remove the <code class=\"inlineCode___KhxNe\">--no-install-recommends<\/code> parameter from the command.<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h1 id=\"\u7b2c\u4e8c\u6b65-\u521b\u5efa\u9879\u76ee\" style=\"text-align: center;\"><strong>Step Two: Project Creation<\/strong><\/h1>\n<p>Since the construction of a Linglong format application from source code is required, the <code class=\"inlineCode___KhxNe\">ll-builder create<\/code> operation can be skipped. There is no need to create Linglong-specific folders; instead, you can directly write the <code class=\"inlineCode___KhxNe\">linglong.yaml<\/code> file at the top-level directory of the project source code (<a href=\"https:\/\/linglong.dev\/guide\/ll-builder\/create.html#%E5%AE%8C%E6%95%B4%E7%9A%84linglong-yaml%E9%85%8D%E7%BD%AE\">a complete template file<\/a> can be used from the official website).<\/p>\n<p>&nbsp;<\/p>\n<h1 id=\"\u7b2c\u4e09\u6b65-\u7f16\u8f91-\" style=\"text-align: center;\"><strong>Step Three: Edit the Linglong.yaml File<\/strong><\/h1>\n<p><img loading=\"lazy\" class=\"aligncenter\" src=\"https:\/\/storage.deepin.org\/thread\/202406120158245087_17181574705021.png\" alt=\"\" width=\"875\" height=\"600\" \/><\/p>\n<p>Take this <a href=\"https:\/\/github.com\/zty199\/desktop-entry-editor\/blob\/main\/linglong.yaml\"><code class=\"inlineCode___KhxNe\">linglong.yaml<\/code> <\/a>as an example, and fill in the package metadata as needed.<\/p>\n<p>Since the project is relatively simple and only requires a basic Qt and Dtk environment to build, you can use the <code class=\"inlineCode___KhxNe\">base<\/code> and <code class=\"inlineCode___KhxNe\">runtime<\/code> shown in the template file.<\/p>\n<p>For more complex build environments, you can refer to <a href=\"https:\/\/linglong.dev\/guide\/ll-builder\/manifests.html#%E8%AE%A1%E7%AE%97%E5%99%A8\">the Calculator build process<\/a>, pull the required dependency code before building the application, and prioritize building the necessary dependencies.<\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Understanding the \"Prefix\" for Installation Locations<\/strong><\/h3>\n<p>In the way we are familiar with, generally, executable files need to be placed in the <code class=\"inlineCode___KhxNe\">\/usr\/bin<\/code> directory so that they can be found when executed in the terminal. <code class=\"inlineCode___KhxNe\">.desktop<\/code> files provide the entry point for launching, and to see the application icon in the launcher, they are generally placed in the <code class=\"inlineCode___KhxNe\">\/usr\/share\/applications<\/code> directory; and image files are placed in the specific icon theme and size classification folders under the <code class=\"inlineCode___KhxNe\">\/usr\/share\/icons<\/code> directory. Here, <code class=\"inlineCode___KhxNe\">\/usr<\/code> is the \"prefix\" for the installation location of all files.<\/p>\n<p>According to <a href=\"https:\/\/www.gnu.org\/prep\/standards\/html_node\/Directory-Variables.html\">the GNU Coding Standards<\/a>, the default value for the \"prefix\" is generally <code class=\"inlineCode___KhxNe\">\/usr\/local<\/code>; and when building a deb format software package, the <code class=\"inlineCode___KhxNe\">\/usr<\/code> prefix is usually used.<\/p>\n<p>When the Linglong container starts, the container content <code class=\"inlineCode___KhxNe\">files<\/code> folder is mounted to the <code class=\"inlineCode___KhxNe\">\/opt\/apps\/${appid}<\/code> directory, so it can be approximated that the \"prefix\" is <code class=\"inlineCode___KhxNe\">\/opt\/apps\/${appid}\/files<\/code>. By the same token, the actual location of the executable file is <code class=\"inlineCode___KhxNe\">\/opt\/apps\/${appid}\/files\/bin\/executable_name<\/code>, so the <code class=\"inlineCode___KhxNe\">command<\/code> startup instruction part in the <code class=\"inlineCode___KhxNe\">linglong.yaml<\/code> also needs to be filled out in this way, rather than the common <code class=\"inlineCode___KhxNe\">\/usr\/bin\/executable_name<\/code>.<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"\u68c0\u67e5\u4fee\u6539\u5de5\u7a0b\u6e90\u4ee3\u7801\"><strong>Inspect and Modify the Source Code of the Project<\/strong><\/h3>\n<p>Having understood the concept of the \"prefix,\" you should check the installation location prefix of the project's source code. In a qmake project, the default installation location prefix is generally the <code class=\"inlineCode___KhxNe\">\/opt\/$${TARGET}<\/code> directory, where the executable files are placed in the <code class=\"inlineCode___KhxNe\">\/opt\/$${TARGET}\/bin<\/code> directory. Here, you may need to modify the <code class=\"inlineCode___KhxNe\">.pro<\/code> file, changing the prefix to <code class=\"inlineCode___KhxNe\">\/opt\/apps\/${appid}\/files<\/code> to ensure the correct file location after the Linglong container starts.<\/p>\n<blockquote><p>Alternatively, as shown in the construction of the<a href=\"https:\/\/linglong.dev\/guide\/ll-builder\/manifests.html#%E8%AE%A1%E7%AE%97%E5%99%A8\"> \"Calculator,\"<\/a> pass the installation location prefix from the outside through qmake parameters and parse <code class=\"inlineCode___KhxNe\">${PREFIX}<\/code> in the <code class=\"inlineCode___KhxNe\">.pro<\/code> file to control the file installation location.<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h1 id=\"\u7b2c\u56db\u6b65-\u6784\u5efa\u5e94\u7528\" style=\"text-align: center;\"><strong>Step Four: Build the Application<\/strong><\/h1>\n<p>Open a terminal in the top-level directory of the project source code (the same level as the linglong.yaml directory) and execute the <code class=\"inlineCode___KhxNe\">ll-builder build<\/code> command.<\/p>\n<p><img class=\"aligncenter\" src=\"https:\/\/storage.deepin.org\/thread\/20240605121452715_2.png\" alt=\"2.png\" \/><\/p>\n<p><img class=\"aligncenter\" src=\"https:\/\/storage.deepin.org\/thread\/202406051215034759_3.png\" alt=\"3.png\" \/><\/p>\n<blockquote><p>During the initial build, it is necessary to download the specified <code class=\"inlineCode___KhxNe\">base<\/code> and <code class=\"inlineCode___KhxNe\">runtime<\/code>, which may take a considerable amount of time and requires patient waiting.<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h1 id=\"\u7b2c\u4e94\u6b65-\u6d4b\u8bd5\u8fd0\u884c\u5e94\u7528\" style=\"text-align: center;\"><strong>Step Five: Test and Run the Application<\/strong><\/h1>\n<p>Open a terminal in the top-level directory of the project source code (the same level as the linglong.yaml file) and execute the command <code class=\"inlineCode___KhxNe\">ll-builder run --exec executable_program_name<\/code> to test the launch of the application within the Linglong container environment.<\/p>\n<p><img class=\"aligncenter\" src=\"https:\/\/storage.deepin.org\/thread\/202406051215131349_4.png\" alt=\"4.png\" \/><\/p>\n<blockquote><p>If\u00a0 the project source code is correct. You can check if the executable file has been generated in the <code class=\"inlineCode___KhxNe\">linglong\/output\/runtime\/files\/bin<\/code> directory under the top-level directory of the project.<\/p>\n<div class=\"MuiBox-root css-3ztqy4\">\n<div id=\"chat-segment-cpkg9j5vbf6u9j020stg\" class=\"segment___n0QmU left___gUK6C\">\n<div class=\"container___hZllz\">\n<div class=\"main___dsnkV\">\n<div class=\"content___hMdwe\">\n<div class=\"markdown___Ho3m0\">\n<p>If the application fails to launch, refer to the documentation for debugging within the container.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<h1 id=\"\u7b2c\u516d\u6b65-\u5bfc\u51fa-layer-\u6587\u4ef6\" style=\"text-align: center;\"><strong>Step Six: Export the Layer File<\/strong><\/h1>\n<p>Open a terminal in the top-level directory of the project source code (the same level as the linglong.yaml file) and execute the <code class=\"inlineCode___KhxNe\">ll-builder export<\/code> command to generate the files <code class=\"inlineCode___KhxNe\">${appid}_${version}_${arch}_develop.layer<\/code> and <code class=\"inlineCode___KhxNe\">${appid}_${version}_${arch}runtime.layer<\/code> in the directory.<\/p>\n<p><img class=\"aligncenter\" src=\"https:\/\/storage.deepin.org\/thread\/202406051215218081_5.png\" alt=\"5.png\" \/><\/p>\n<p>&nbsp;<\/p>\n<h1 style=\"text-align: center;\"><strong>Step Seven: Test Installation of the Layer File<\/strong><\/h1>\n<p>Open a terminal in the top-level directory of the project source code (the same level as the linglong.yaml file), type <code class=\"inlineCode___KhxNe\">ll-cli install<\/code>, and after a space, drag the <code class=\"inlineCode___KhxNe\">runtime.layer<\/code> file from the folder into the terminal and press Enter to execute, which will install the layer file into the local Linglong environment.<\/p>\n<p><img class=\"aligncenter\" src=\"https:\/\/storage.deepin.org\/thread\/202406051215271077_6.png\" alt=\"6.png\" \/><\/p>\n<p>After the installation is successful, you should be able to see the application in the launcher and test it by starting and using it.<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter\" src=\"https:\/\/storage.deepin.org\/thread\/202406051215317887_7.png\" alt=\"7.png\" width=\"728\" height=\"682\" \/><\/p>\n<blockquote><p>If the application cannot be found in the launcher, please check whether the file installation location in the project source code is correct. You can check if a <code class=\"inlineCode___KhxNe\">.desktop<\/code> file has been generated in the <code class=\"inlineCode___KhxNe\">linglong\/output\/runtime\/entries\/share\/applications<\/code> directory under the top-level directory of the project.<\/p>\n<p>If there is a failure to start, you can view the corresponding <code class=\"inlineCode___KhxNe\">.desktop<\/code> file and copy the content of the Exec field to execute in the terminal to observe the startup output log. If there is a prompt that the Linglong corresponding version of the <code class=\"inlineCode___KhxNe\">base<\/code> or <code class=\"inlineCode___KhxNe\">runtime<\/code> environment is missing, you will need to manually execute <code class=\"inlineCode___KhxNe\">ll-cli install environment_name\/version_number<\/code> to install and troubleshoot (e.g., <code class=\"inlineCode___KhxNe\">ll-cli install org.deepin.Runtime\/23.0.1<\/code>).<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>With this, the process of building a Linglong format application from source code has been completed.<\/p>\n<p>The example project in this article uses qmake for building, has simple dependencies, and supports setting the file installation location by passing in <code class=\"inlineCode___KhxNe\">${PREFIX}<\/code> from the outside during the build. It is very simple to build it as a Linglong format application. If the project uses cmake or other tools for building, similarly, you need to modify the installation prefix within the project or pass parameters in the build section of <code class=\"inlineCode___KhxNe\">linglong.yaml<\/code> to set it. Otherwise, even if the build is successful, there may be various issues such as the executable file not being found within the container, or no icons appearing in the launcher after installation.<\/p>\n<p>&nbsp;<\/p>\n<h1><strong>About [PM Direct]<\/strong><\/h1>\n<p><strong>[PM Direct]\u00a0<\/strong>is a new feature launched by the deepin community in May 2024. In this column, we will invite product managers from various products to share and exchange interesting and useful deepin or Linux-related applications with everyone. The product managers will also engage in discussions and Q&amp;A sessions with all users on the deepin forum.<\/p>\n<p>Today's article comes from the deepin Community Store Product Manager, who is also a forum user of the deepin community known as <strong>[\u5fd8\u8bb0\u3001\u8fc7\u53bb]<\/strong>. We hope everyone will continue to follow the deepin forum's feature column\u00a0<strong>[PM Direct].<\/strong><\/p>\n<p>&nbsp;<\/p>\n<h1><strong>Appendix:<\/strong><\/h1>\n<article id=\"post-33497\" class=\"post-33497 post type-post status-publish format-standard hentry category-community-activities\">\n<div class=\"entry-content\">\n<p><b>1\uff09Linglong Official Documentation\uff1a<\/b><a href=\"https:\/\/linglong.dev\/guide\/ll-builder\/introduction.html\">https:\/\/linglong.dev\/guide\/ll-builder\/introduction.html<\/a><\/p>\n<p><strong>2)\u00a0 deepin Previous Versions (Including deepin V15):\u00a0<\/strong><a href=\"https:\/\/distrowatch.com\/table.php?distribution=deepin\"> https:\/\/distrowatch.com\/table.php?distribution=deepin<\/a><\/p>\n<div>\n<h1><\/h1>\n<\/div>\n<\/div>\n<\/article>\n<p style=\"text-align: right;\">Content source: deepin community<br \/>\nReprinted with attribution<\/p>","protected":false},"excerpt":{"rendered":"<p>Please first read the official Linglong documentation. This article uses the construction of desktop-entry-editor as an example. The project has relatively simple dependencies and only requires the basic runtime environment provided by default in the official Linglong documentation to be successfully built and run. Step One: Preliminary Preparations Execute the following command in the terminal: sudo apt install linglong-builder --no-install-recommends Install the ll-builder tool. Since the recommended installation has many dependencies, they are skipped in this instance. If needed, simply remove the --no-install-recommends parameter from the command. &nbsp; Step Two: Project Creation Since the construction of a Linglong format application ...<a href=https:\/\/www.deepin.org.cn\/en\/building-linglong-format-applications-from-source-code\/>Read more<\/a><\/p>\n","protected":false},"author":11164,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[75,93],"tags":[],"_links":{"self":[{"href":"https:\/\/www.deepin.org.cn\/en\/wp-json\/wp\/v2\/posts\/34008"}],"collection":[{"href":"https:\/\/www.deepin.org.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.deepin.org.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.deepin.org.cn\/en\/wp-json\/wp\/v2\/users\/11164"}],"replies":[{"embeddable":true,"href":"https:\/\/www.deepin.org.cn\/en\/wp-json\/wp\/v2\/comments?post=34008"}],"version-history":[{"count":5,"href":"https:\/\/www.deepin.org.cn\/en\/wp-json\/wp\/v2\/posts\/34008\/revisions"}],"predecessor-version":[{"id":34014,"href":"https:\/\/www.deepin.org.cn\/en\/wp-json\/wp\/v2\/posts\/34008\/revisions\/34014"}],"wp:attachment":[{"href":"https:\/\/www.deepin.org.cn\/en\/wp-json\/wp\/v2\/media?parent=34008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.deepin.org.cn\/en\/wp-json\/wp\/v2\/categories?post=34008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.deepin.org.cn\/en\/wp-json\/wp\/v2\/tags?post=34008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}