Allow building the build system using cargo

Rust's build system only handles cargo, not rustc.
This commit is contained in:
bjorn3 2023-02-15 18:23:11 +00:00
parent ce3f300e40
commit d0b8896189
20 changed files with 75 additions and 80 deletions

View File

@ -10,7 +10,7 @@ task:
folder: target
prepare_script:
- . $HOME/.cargo/env
- ./y.rs prepare
- ./y.sh prepare
test_script:
- . $HOME/.cargo/env
- ./y.rs test
- ./y.sh test

View File

@ -46,12 +46,12 @@ jobs:
run: rustup set default-host x86_64-pc-windows-gnu
- name: Prepare dependencies
run: ./y.rs prepare
run: ./y.sh prepare
- name: Build
run: ./y.rs build --sysroot none
run: ./y.sh build --sysroot none
- name: Test abi-cafe
env:
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
run: ./y.rs abi-cafe
run: ./y.sh abi-cafe

View File

@ -19,7 +19,7 @@ jobs:
- name: Rustfmt
run: |
cargo fmt --check
rustfmt --check build_system/mod.rs
rustfmt --check build_system/main.rs
rustfmt --check example/*
@ -91,15 +91,15 @@ jobs:
sudo apt-get install -y gcc-s390x-linux-gnu qemu-user
- name: Prepare dependencies
run: ./y.rs prepare
run: ./y.sh prepare
- name: Build
run: ./y.rs build --sysroot none
run: ./y.sh build --sysroot none
- name: Test
env:
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
run: ./y.rs test
run: ./y.sh test
- name: Install LLVM standard library
run: rustup target add ${{ matrix.env.TARGET_TRIPLE }}
@ -111,7 +111,7 @@ jobs:
if: matrix.os != 'windows-latest' || matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu'
env:
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
run: ./y.rs test --sysroot llvm --no-unstable-features
run: ./y.sh test --sysroot llvm --no-unstable-features
# This job doesn't use cg_clif in any way. It checks that all cg_clif tests work with cg_llvm too.
@ -165,13 +165,13 @@ jobs:
run: cargo install hyperfine || true
- name: Prepare dependencies
run: ./y.rs prepare
run: ./y.sh prepare
- name: Build
run: CI_OPT=1 ./y.rs build --sysroot none
run: CI_OPT=1 ./y.sh build --sysroot none
- name: Benchmark
run: CI_OPT=1 ./y.rs bench
run: CI_OPT=1 ./y.sh bench
dist:
@ -224,13 +224,13 @@ jobs:
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
- name: Prepare dependencies
run: ./y.rs prepare
run: ./y.sh prepare
- name: Build backend
run: CI_OPT=1 ./y.rs build --sysroot none
run: CI_OPT=1 ./y.sh build --sysroot none
- name: Build sysroot
run: CI_OPT=1 ./y.rs build
run: CI_OPT=1 ./y.sh build
- name: Package prebuilt cg_clif
run: tar cvfJ cg_clif.tar.xz dist

View File

@ -18,7 +18,7 @@ jobs:
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
- name: Prepare dependencies
run: ./y.rs prepare
run: ./y.sh prepare
- name: Test
run: ./scripts/test_bootstrap.sh
@ -38,7 +38,7 @@ jobs:
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
- name: Prepare dependencies
run: ./y.rs prepare
run: ./y.sh prepare
- name: Test
run: ./scripts/test_rustc_tests.sh

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
/target
/build_system/target
**/*.rs.bk
*.rlib
*.o

View File

@ -6,9 +6,10 @@
"rust-analyzer.imports.granularity.enforce": true,
"rust-analyzer.imports.granularity.group": "module",
"rust-analyzer.imports.prefix": "crate",
"rust-analyzer.cargo.features": ["unstable-features", "__check_build_system_using_ra"],
"rust-analyzer.cargo.features": ["unstable-features"],
"rust-analyzer.linkedProjects": [
"./Cargo.toml",
"./build_system/Cargo.toml",
{
"crates": [
{

View File

@ -3,13 +3,6 @@ name = "rustc_codegen_cranelift"
version = "0.1.0"
edition = "2021"
[[bin]]
# This is used just to teach rust-analyzer how to check the build system. required-features is used
# to disable it for regular builds.
name = "y"
path = "./y.rs"
required-features = ["__check_build_system_using_ra"]
[lib]
crate-type = ["dylib"]
@ -45,7 +38,6 @@ smallvec = "1.8.1"
unstable-features = ["jit", "inline_asm"]
jit = ["cranelift-jit", "libloading"]
inline_asm = []
__check_build_system_using_ra = []
[package.metadata.rust-analyzer]
rustc_private = true

View File

@ -10,8 +10,8 @@ If not please open an issue.
```bash
$ git clone https://github.com/bjorn3/rustc_codegen_cranelift
$ cd rustc_codegen_cranelift
$ ./y.rs prepare
$ ./y.rs build
$ ./y.sh prepare
$ ./y.sh build
```
To run the test suite replace the last command with:
@ -20,7 +20,7 @@ To run the test suite replace the last command with:
$ ./test.sh
```
For more docs on how to build and test see [build_system/usage.txt](build_system/usage.txt) or the help message of `./y.rs`.
For more docs on how to build and test see [build_system/usage.txt](build_system/usage.txt) or the help message of `./y.sh`.
## Precompiled builds
@ -35,7 +35,7 @@ If you want to use `cargo clif build` instead of having to specify the full path
rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects.
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.rs prepare` and `y.rs build` or `test.sh`).
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.sh prepare` and `y.sh build` or `test.sh`).
In the directory with your project (where you can do the usual `cargo build`), run:

7
build_system/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "y"
version = "0.1.0"

13
build_system/Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "y"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "y"
path = "main.rs"
[features]
unstable-features = [] # for rust-analyzer
# Do not add any dependencies

View File

@ -225,7 +225,7 @@ fn build_clif_sysroot_for_triple(
match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) {
Err(e) => {
eprintln!("Failed to get rustc version for patched sysroot source: {}", e);
eprintln!("Hint: Try `./y.rs prepare` to patch the sysroot source");
eprintln!("Hint: Try `./y.sh prepare` to patch the sysroot source");
process::exit(1);
}
Ok(source_version) => {
@ -234,7 +234,7 @@ fn build_clif_sysroot_for_triple(
eprintln!("The patched sysroot source is outdated");
eprintln!("Source version: {}", source_version.trim());
eprintln!("Rustc version: {}", rustc_version.trim());
eprintln!("Hint: Try `./y.rs prepare` to update the patched sysroot source");
eprintln!("Hint: Try `./y.sh prepare` to update the patched sysroot source");
process::exit(1);
}
}

View File

@ -1,3 +1,7 @@
#![warn(rust_2018_idioms)]
#![warn(unused_lifetimes)]
#![warn(unreachable_pub)]
use std::env;
use std::path::PathBuf;
use std::process;
@ -37,19 +41,19 @@ enum Command {
}
#[derive(Copy, Clone, Debug)]
pub(crate) enum SysrootKind {
enum SysrootKind {
None,
Clif,
Llvm,
}
#[derive(Clone, Debug)]
pub(crate) enum CodegenBackend {
enum CodegenBackend {
Local(PathBuf),
Builtin(String),
}
pub(crate) fn main() {
fn main() {
if env::var("RUST_BACKTRACE").is_err() {
env::set_var("RUST_BACKTRACE", "1");
}

View File

@ -1,11 +1,11 @@
The build system of cg_clif.
USAGE:
./y.rs prepare [--out-dir DIR] [--download-dir DIR]
./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.rs abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.rs bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.sh prepare [--out-dir DIR] [--download-dir DIR]
./y.sh build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.sh test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.sh abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.sh bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
OPTIONS:
--debug
@ -40,7 +40,7 @@ REQUIREMENTS:
* Rustup: By default rustup is used to install the right nightly version. If you don't want to
use rustup, you can manually install the nightly version indicated by rust-toolchain.toml and
point the CARGO, RUSTC and RUSTDOC env vars to the right executables.
* Git: `./y.rs prepare` uses git for applying patches and on Windows for downloading test repos.
* Curl and tar (non-Windows only): Used by `./y.rs prepare` to download a single commit for
* Git: `./y.sh prepare` uses git for applying patches and on Windows for downloading test repos.
* Curl and tar (non-Windows only): Used by `./y.sh prepare` to download a single commit for
repos. Git will be used to clone the whole repo when using Windows.
* [Hyperfine](https://github.com/sharkdp/hyperfine/): Used for benchmarking with `./y.rs bench`.
* [Hyperfine](https://github.com/sharkdp/hyperfine/): Used for benchmarking with `./y.sh bench`.

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e
rm -rf target/ download/ build/ dist/ y.bin y.bin.dSYM y.exe y.pdb
rm -rf target/ build_system/target download/ build/ dist/ y.bin y.bin.dSYM y.exe y.pdb
# Kept for now in case someone updates their checkout of cg_clif before running clean_all.sh
# FIXME remove at some point in the future

View File

@ -2,7 +2,7 @@
rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects.
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.rs prepare` and `y.rs build` or `test.sh`).
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.sh prepare` and `y.sh build` or `test.sh`).
## Cargo

View File

@ -32,7 +32,7 @@ case $1 in
./clean_all.sh
./y.rs prepare
./y.sh prepare
(cd download/sysroot && cargo update && cargo fetch && cp Cargo.lock ../../build_sysroot/)
;;

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e
./y.rs build --no-unstable-features
./y.sh build --no-unstable-features
echo "[SETUP] Rust fork"
git clone https://github.com/rust-lang/rust.git || true

View File

@ -1,2 +1,2 @@
#!/usr/bin/env bash
exec ./y.rs test "$@"
exec ./y.sh test "$@"

33
y.rs
View File

@ -1,35 +1,6 @@
#!/usr/bin/env bash
#![deny(unsafe_code)] /*This line is ignored by bash
# This block is ignored by rustc
set -e
echo "[BUILD] y.rs" 1>&2
rustc $0 -o ${0/.rs/.bin} -Cdebuginfo=1 --edition 2021
exec ${0/.rs/.bin} $@
echo "Warning: y.rs is a deprecated alias for y.sh" 1>&2
exec ./y.sh "$@"
*/
#![warn(rust_2018_idioms)]
#![warn(unused_lifetimes)]
#![warn(unreachable_pub)]
//! The build system for cg_clif
//!
//! # Manual compilation
//!
//! If your system doesn't support shell scripts you can manually compile and run this file using
//! for example:
//!
//! ```shell
//! $ rustc y.rs -o y.bin
//! $ ./y.bin
//! ```
//!
//! # Naming
//!
//! The name `y.rs` was chosen to not conflict with rustc's `x.py`.
#[path = "build_system/mod.rs"]
mod build_system;
fn main() {
build_system::main();
}

6
y.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
echo "[BUILD] build system" 1>&2
rustc build_system/main.rs -o y.bin -Cdebuginfo=1 --edition 2021
exec ./y.bin "$@"