How to build out-of-tree Fuchsia OS program

孤者浪人 提交于 2021-01-28 09:39:15

问题


After installing and building Fuchsia OS, I can modify the string in the example hello world program from "Hello, World!\n" to "Hello, Fuchsia!\n". Then I build and execute the code which produces the expected string "Hello, Fuchsia!" using:

cd fuchsia
fx set bringup.x64 --with //examples/hello_world
fx build; fx qemu
hello_world_cpp

This is fine for understanding how to change part of the Fuchsia "distribution". How do I create my own program outside of the fuchsia tree? I assume one would do normally this when creating program for running on Fuchsia OS so that one can manage the source cleanly.


回答1:


Answer

The third_party directory is meant for modules that are managed outside of the Fuchsia tree. In the top-level .gitignore the directory is excluded (link):

/third_party/*

You can see that this folder is mostly empty in git (link). It is first populated during bootstrap (link), which internally uses jiri update to fetch repos specified in the integration manifest (e.g. for third_party).

You would maintain your module in a separate git repo. For development, you would clone this repo into a sub-directory in third-party. Because of the .gitignore entry, it will not be tracked by the Fuchsia git.

Example

Files:

third_party/hello_world/BUILD.gn
third_party/hello_world/hello_world.cc

BUILD.gn:

import("//build/package.gni")

group("hello_world") {
  deps = [ ":hello-world-cpp" ]
}

executable("bin") {
  output_name = "my_hello_world_cpp"
  sources = [ "hello_world.cc" ]
}

package("hello-world-cpp") {
  deps = [ ":bin" ]
  binaries = [
    {
      name = "my_hello_world_cpp"
    },
  ]
}

hello_world.cc:

#include <iostream>

int main(int argc, char** argv) {
  std::cout << "Hello, World (out-of-tree)!" << std::endl;
  return 0;
}

Build and run:

$ fx set bringup.x64 --with //third_party/hello_world
$ fx build
$ fx qemu
$ my_hello_world_cpp
Hello, World (out-of-tree)!


来源:https://stackoverflow.com/questions/60896095/how-to-build-out-of-tree-fuchsia-os-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!