mavlink / qgroundcontrol

Cross-platform ground control station for drones (Android, iOS, Mac OS, Linux, Windows)
http://qgroundcontrol.io
3.28k stars 3.61k forks source link

prevent downloads during build #11617

Open christianrauch opened 4 months ago

christianrauch commented 4 months ago

The build process uses FetchContent_Declare to download additional sources during the build process, instead of git submodules. Some packaging processes, such as snap and flatpak, run builds in a sandbox and prevent; and some (Debian) discourage network access during build time and expect all sources to be available before the build.

On master, the add_subdirectory(Geo) tries to fetch https://github.com/geographiclib/geographiclib.git during the build, which causes build issues on flatpak:

[1/9] Creating directories for 'geographiclib-populate'
[1/9] Performing download step (git clone) for 'geographiclib-populate'
Cloning into 'geographiclib-src'...
fatal: unable to access 'https://github.com/geographiclib/geographiclib.git/': Could not resolve host: github.com
Cloning into 'geographiclib-src'...
fatal: unable to access 'https://github.com/geographiclib/geographiclib.git/': Could not resolve host: github.com
Cloning into 'geographiclib-src'...
fatal: unable to access 'https://github.com/geographiclib/geographiclib.git/': Could not resolve host: github.com
-- Had to git clone more than once: 3 times.
CMake Error at geographiclib-subbuild/geographiclib-populate-prefix/tmp/geographiclib-populate-gitclone.cmake:39 (message):
  Failed to clone repository:
  'https://github.com/geographiclib/geographiclib.git'

Would it be possible to add geographiclib as a submodule to the git project in order to allow builds in sandboxed/isolated environments?

HTRamsey commented 4 months ago

I'm largely unfamiliar with building via flatpaks, but I do understand they are generally preferred over appimages for security & versioning/updating reasons. Do other repos that build with flatpak just not let cmake handle dependencies at all? I believe @DonLakeFlyer generally prefers to use submodules too.

One of the reasons I was in favor of using cmake to handle dependencies was because it's really easy to separate dependencies based on platform (which is nice because we started running out of space in the github CI builds). Also, how would you handle the parts where you get dependencies from somewhere other than github? One example being that cmake downloads gstreamer stuff during the build. I did intend on changing the FetchContent command to use FIND_PACKAGE_ARGS to find installed versions of dependencies at some point, so that could be a solution to geographiclib at least.

christianrauch commented 4 months ago

Do other repos that build with flatpak just not let cmake handle dependencies at all?

Yes. At least for flathub, all builds run in a sandbox that prevents network access etc. during the build. All sources have to be specified before the build.

Also, how would you handle the parts where you get dependencies from somewhere other than github?

I am not entirely sure what you mean. If you add subprojects as submodules, you can add any remote repo, not just those from github.com. Other dependencies can usually be installed with platform-specific package managers (apt, dnf, brew, vcpkg, ...). Finally, you can always install dependencies from source. The latter is what is usually done for flatpaks.

heeplr commented 3 months ago

This also breaks gentoo live builds. Network access during configure phase is always disabled for security reasons.

I believe @DonLakeFlyer generally prefers to use submodules too.

Submodules would be the preferred way.

One of the reasons I was in favor of using cmake to handle dependencies was because it's really easy to separate dependencies based on platform (which is nice because we started running out of space in the github CI builds).

That could be a problem. Maybe different branches for each platform could solve this. Not sure.

Also, how would you handle the parts where you get dependencies from somewhere other than github?

As long as dependencies use git, other sources besides github should be no problem.

heeplr commented 3 months ago

btw. this affects all sources fetched by cmake.

FetchContent shouldn't attempt to download, if the submodule has already been fetched. It should (silently) succeed. That way it would work without git fetch'ing all submodules (i.e. non-recursive clone).

To avoid a cluttered CI environment, maybe submodules could then be git fetch'd manually or filtered with some approach like: https://stackoverflow.com/questions/56745097/exclude-submodule-of-a-submodule

HTRamsey commented 3 months ago

I will look into this once the custom build stuff is done. I believe we only have one submodule that doesn't use git but it's for Android only (this was actually my intended question rather than GitHub, but I realized it doesn't matter if it's not Linux). Maybe there's some setup where we can leave all the other build platforms alone besides linux