Abstract:The RISC-V instruction set architecture, characterized by its openness and modular design, promotes innovation and customization in processor architecture, while simultaneously introducing severe software ecosystem fragmentation. Traditional cross-platform software build mechanisms, such as on-site compilation, IFUNC, and Multilib, encounter significant challenges in the RISC-V ecosystem, including limited compatibility, high maintenance overhead, and insufficient optimization granularity, which highlights the need for new solutions. To address these issues, this study proposes a compatibility-aware multi-level compilation method for the RISC-V platform—RuyiBuild toolchain. By adopting LLVM IR as the intermediate representation and integrating a non-intrusive compilation interception mechanism, transparent adaptation to existing software build systems is achieved. As a result, the generated operating system software packages simultaneously support compatibility across heterogeneous combinations of RISC-V extension instruction sets and adaptive, extension-aware optimizations tailored to target execution platforms. This approach systematically resolves the dual-objective challenge of achieving both high-performance binary optimization and broad compatibility under diverse instruction set extensions and platform variations inherent in the RISC-V ecosystem. Centered on the extraction, deployment, transformation, and optimization of LLVM IR, RuyiBuild establishes a comprehensive framework for cross-platform software distribution and fine-grained optimization. The framework consists of four core mechanisms: a transparent dual-path compilation and LLVM IR extraction mechanism; a dynamic library LLVM IR aggregation and link-time transformation mechanism; an LLVM IR deployment and automated RPM integration mechanism; a client-cloud collaborative LLVM IR dynamic transformation and resource-adaptive scheduling mechanism. From an implementation perspective, the RuyiBuild toolchain encapsulates compilation tools and system commands, enabling full-path LLVM IR extraction and distribution without modifying source code or existing build systems. During deployment, synchronized distribution of LLVM IR and traditional binaries is supported. Furthermore, to facilitate performance optimization across various target devices and microarchitectures, client-side resource-aware deferred transformation and cloud-side multi-architecture adaptation with dynamic LLVM IR transformation are provided. Experimental results show that RuyiBuild supports deployment across a wide range of RISC-V instruction set extensions and microarchitecture combinations, while achieving a favorable balance among performance, compatibility, build overhead, and deployment complexity. Consequently, this study provides a novel and effective solution for software build, deployment, and adaptation in the RISC-V ecosystem, offering both academic value and practical potential.