Anki/build/configure/src/main.rs
Kai Knoblich bd703a8b6d Add support for offline builds (#2963)
* CONTRIBUTORS: Add myself to the contributors list

* Add support for offline builds

Downloading files during build time is a non-starter for FreeBSD ports
(and presumably for other *BSD ports and some Linux distros as well).

In order to still be able to build Anki successfully, two new
environment variables have been added that can be set accordingly:

* NO_VENV: If set, the Python system environment is used instead of
  a venv. This is necessary if there are no usable Python wheels for a
  platform, e.g. PyQt6.

* OFFLINE_BUILD: If set, the git repository synchronization (translation
  files, build hash, etc.) is skipped.

To successfully build Anki offline, following conditions must be met:

1. All required dependencies (node, Python, rust, yarn, etc.) must be
   present in the build environment.

2. The offline repositories for the translation files must be
   copied/linked to ftl/qt-repo and ftl/core-repo.

3. The Python pseudo venv needs to be setup:

   $ mkdir out/pyenv/bin
   $ ln -s /path/to/python out/pyenv/bin/python
   $ ln -s /path/to/protoc-gen-mypy out/pyenv/bin/protoc-gen-mypy

4. Create the offline cache for yarn and use its own environment
   variable YARN_CACHE_FOLDER to it:

   YARN_CACHE_FOLDER=/path/to/the/yarn/cache
   $ /path/to/yarn install --ignore-scripts

5. Build Anki:

   $ /path/to/cargo build --package runner --release --verbose --verbose
   $ OFFLINE_BUILD=1 \
     NO_VENV=1 \
     ${WRKSRC}/out/rust/release/runner build wheels
2024-01-31 09:13:46 +10:00

82 lines
1.8 KiB
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
mod aqt;
mod bundle;
mod platform;
mod pylib;
mod python;
mod rust;
mod web;
use std::env;
use anyhow::Result;
use aqt::build_and_check_aqt;
use bundle::build_bundle;
use ninja_gen::glob;
use ninja_gen::inputs;
use ninja_gen::protobuf::check_proto;
use ninja_gen::protobuf::setup_protoc;
use ninja_gen::python::setup_python;
use ninja_gen::Build;
use pylib::build_pylib;
use pylib::check_pylib;
use python::check_python;
use python::setup_venv;
use python::setup_venv_stub;
use rust::build_rust;
use rust::check_minilints;
use rust::check_rust;
use web::build_and_check_web;
use web::check_sql;
use crate::python::setup_sphix;
fn anki_version() -> String {
std::fs::read_to_string(".version")
.unwrap()
.trim()
.to_string()
}
fn main() -> Result<()> {
let mut build = Build::new()?;
let build = &mut build;
setup_protoc(build)?;
check_proto(build, inputs![glob!["proto/**/*.proto"]])?;
setup_python(build)?;
if env::var("NO_VENV").is_ok() {
println!("NO_VENV is set, using Python system environment.");
setup_venv_stub(build)?;
} else {
setup_venv(build)?;
}
build_rust(build)?;
build_pylib(build)?;
build_and_check_web(build)?;
build_and_check_aqt(build)?;
build_bundle(build)?;
if env::var("OFFLINE_BUILD").is_err() {
println!("OFFLINE_BUILD is set, skipping build of offline documentation.");
setup_sphix(build)?;
}
check_rust(build)?;
check_pylib(build)?;
check_python(build)?;
check_sql(build)?;
check_minilints(build)?;
build.trailing_text = "default pylib qt\n".into();
build.write_build_file()?;
Ok(())
}