Skip to content

llvm.download-ci-llvm cannot be set to true #141782

@smallprogram

Description

@smallprogram

Summary

When I use the openwrt source code to build the system, the compilation will depend on rust, where the Makefile of rust is as follows:

# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2023 Luca Barbato and Donald Hoskins

include $(TOPDIR)/rules.mk

PKG_NAME:=rust
PKG_VERSION:=1.87.0
PKG_RELEASE:=1

PKG_SOURCE:=rustc-$(PKG_VERSION)-src.tar.gz
PKG_SOURCE_URL:=https://static.rust-lang.org/dist/
PKG_HASH:=149bb9fd29be592da4e87900fc68f0629a37bf6850b46339dd44434c04fd8e76
HOST_BUILD_DIR:=$(BUILD_DIR)/host/rustc-$(PKG_VERSION)-src

PKG_MAINTAINER:=Luca Barbato <lu_zero@luminem.org>
PKG_LICENSE:=Apache-2.0 MIT
PKG_LICENSE_FILES:=LICENSE-APACHE LICENSE-MIT

PKG_HOST_ONLY:=1
PKG_BUILD_FLAGS:=no-mips16

include $(INCLUDE_DIR)/host-build.mk
include $(INCLUDE_DIR)/package.mk
include ./rust-values.mk

define Package/rust
SECTION:=lang
CATEGORY:=Languages
SUBMENU:=Rust
TITLE:=Rust Programming Language Compiler
URL:=https://www.rust-lang.org/
DEPENDS:=$(RUST_ARCH_DEPENDS)
endef

define Package/rust/description
Rust is a multi-paradigm, general-purpose programming language designed for performance
and safety, especially safe concurrency. Rust is syntactically similar to C++, but can
guarantee memory safety by using a borrow checker to validate references.
endef

define Package/rust/config
source "$(SOURCE)/Config.in"
endef

# Rust-lang has an uninstall script
RUST_UNINSTALL:=$(STAGING_DIR)/host/lib/rustlib/uninstall.sh

# Target Flags
TARGET_CONFIGURE_ARGS = \
--set=target.$(RUSTC_TARGET_ARCH).ar=$(TARGET_AR) \
--set=target.$(RUSTC_TARGET_ARCH).cc=$(TARGET_CC_NOCACHE) \
--set=target.$(RUSTC_TARGET_ARCH).cxx=$(TARGET_CXX_NOCACHE) \
--set=target.$(RUSTC_TARGET_ARCH).linker=$(TARGET_CC_NOCACHE) \
--set=target.$(RUSTC_TARGET_ARCH).ranlib=$(TARGET_RANLIB) \
--set=target.$(RUSTC_TARGET_ARCH).crt-static=false \
$(if $(CONFIG_USE_MUSL),--set=target.$(RUSTC_TARGET_ARCH).musl-root=$(TOOLCHAIN_ROOT_DIR))

# CARGO_HOME is an environmental
HOST_CONFIGURE_VARS += CARGO_HOME="$(CARGO_HOME)"

# Rust Configuration Arguments
HOST_CONFIGURE_ARGS = \
--build=$(RUSTC_HOST_ARCH) \
--target=$(RUSTC_TARGET_ARCH),$(RUSTC_HOST_ARCH) \
--host=$(RUSTC_HOST_ARCH) \
--prefix=$(STAGING_DIR)/host \
--bindir=$(STAGING_DIR)/host/bin \
--libdir=$(STAGING_DIR)/host/lib \
--sysconfdir=$(STAGING_DIR)/host/etc \
--datadir=$(STAGING_DIR)/host/share \
--mandir=$(STAGING_DIR)/host/man \
--dist-compression-formats=gz \
--disable-sanitizers \
--release-channel=stable \
--enable-cargo-native-static \
--bootstrap-cache-path=$(DL_DIR)/rustc \
--set=llvm.download-ci-llvm=true \
$(TARGET_CONFIGURE_ARGS)

define Host/Uninstall
# Call the Uninstall script
[ -f $(RUST_UNINSTALL) ] && \
$(BASH) $(RUST_UNINSTALL) || echo No Uninstall
endef

define Host/Compile
$(RUST_SCCACHE_VARS) \
CARGO_HOME=$(CARGO_HOME) \
TARGET_CFLAGS="$(TARGET_CFLAGS)" \
$(PYTHON) $(HOST_BUILD_DIR)/x.py \
--build-dir $(HOST_BUILD_DIR)/build \
dist build-manifest rustc rust-std cargo llvm-tools rust-src
endef

define Host/Install
( \
cd $(HOST_BUILD_DIR)/build/dist ; \
for targz in *.tar.gz; do \
$(STAGING_DIR_HOST)/bin/libdeflate-gzip -dc "$$$$targz" | tar -xf - ; \
done ; \
find . -mindepth 2 -maxdepth 2 -type f -name install.sh \
-execdir bash '{}' --prefix=$(STAGING_DIR)/host --disable-ldconfig \; ; \
)
endef

$(eval $(call HostBuild))
$(eval $(call BuildPackage,rust))

Among them, llvm.download-ci-llvm=true, when the compilation is executed locally, there is no problem, no error, and it can be compiled perfectly. However, when using the Ubuntu-latest system environment (Ubuntu-24.04) in Github Action, an error will appear:

thread 'main' panicked at src/bootstrap/src/core/config/config.rs:3166:21:
llvm.download-ci-llvm cannot be set to true on CI. Use if-unchanged instead.
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Build completed unsuccessfully in 0:00:00
make[3]: *** [Makefile:108: /home/runner/work/auto-build-openwrt/auto-build-openwrt/openwrt/build_dir/target-x86_64_musl/host/rustc-1.87.0-src/.built] Error 1
make[3]: Leaving directory '/home/runner/work/auto-build-openwrt/auto-build-openwrt/openwrt/feeds/packages/lang/rust'
time: package/feeds/packages/rust/host-compile#0.47#0.28#0.74
ERROR: package/feeds/packages/rust [host] failed to build.

I checked your source code and found that

match download_ci_llvm {
StringOrBool::Bool(b) => {
if !b && self.download_rustc_commit.is_some() {
panic!(
"`llvm.download-ci-llvm` cannot be set to `false` if `rust.download-rustc` is set to `true` or `if-unchanged`."
);
}
if b && self.is_running_on_ci {
// On CI, we must always rebuild LLVM if there were any modifications to it
panic!(
"`llvm.download-ci-llvm` cannot be set to `true` on CI. Use `if-unchanged` instead."
);
}
// If download-ci-llvm=true we also want to check that CI llvm is available
b && llvm::is_ci_llvm_available_for_target(self, asserts)
}
StringOrBool::String(s) if s == "if-unchanged" => if_unchanged(),
StringOrBool::String(other) => {
panic!("unrecognized option for download-ci-llvm: {other:?}")
}
}
}

It shows why this error occurs. I know nothing about rust and I don't understand why it needs to detect whether the environment is CI.

I hope this can help solve this problem, thank you.

Operating system

Ubuntu 24.04 Github Action

Link issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions