offline package building in the foul year of 2022

it gets increasingly hard to compile stuff offline, most languages use some kind of own package management, and few get it right. this is a compilation of hacks useful to build stuff offline.

the good

Go

Go is rather easy, just run go mod vendor and every dependency listed in the mod file is downloaded and put into ./vendor. you can just put this folder along the sources and it should build offline, using those sources. while it should switch to offline mode automatically, you can force it with -mod=vendor:

-mod=vendor tells the go command to use the vendor directory. In this mode, the go command will not use the network or the module cache. By default, if the go version in go.mod is 1.14 or higher and a vendor directory is present, the go command acts as if -mod=vendor were used. Otherwise, the go command acts as if -mod=readonly were used.

the bad

rust

this is supposed to work:

cargo vendor vendor

which spits out lines to add to ./.cargo/config.toml. it might work then.

the ugly

cMaKe

this is just plain evil, imho. there are dozens of ways stuff tries to download things. submodules, random git clones, http archive downloads, ...

if stuff is somewhat "standards" compatible, you can add -DFETCHCONTENT_FULLY_DISCONNECTED=ON.

for stuff that is loaded with CPM, you can then place the sources of individual dependencies into a folder and tell CPM to look there with -DCPM_${depname}_SOURCE=$pathtodep. CPM obeys the flag described above.

for things using externalproject_add you might to patch CMakeLists, setting DOWNLOAD_COMMAND "", and copy the sources to "the right place", whereever that might be.

example commands to insert sources

tar

mkdir -p build/dependencies/lib-fltk/builder/fltk-prefix/src/fltk
tar xvf $CWD/fltk-1.3.5-source.tar.gz --strip-components=1 -C build/dependencies/lib-fltk/builder/fltk-prefix/src/fltk

zip

mkdir -p build/lib-sol2
unzip -d build/lib-sol2 $CWD/sol2-3.2.2.zip
mv build/lib-sol2/sol2-3.2.2 build/lib-sol2/src