Allow building the build system using cargo
Rust's build system only handles cargo, not rustc.
This commit is contained in:
parent
ce3f300e40
commit
d0b8896189
@ -10,7 +10,7 @@ task:
|
|||||||
folder: target
|
folder: target
|
||||||
prepare_script:
|
prepare_script:
|
||||||
- . $HOME/.cargo/env
|
- . $HOME/.cargo/env
|
||||||
- ./y.rs prepare
|
- ./y.sh prepare
|
||||||
test_script:
|
test_script:
|
||||||
- . $HOME/.cargo/env
|
- . $HOME/.cargo/env
|
||||||
- ./y.rs test
|
- ./y.sh test
|
||||||
|
6
.github/workflows/abi-cafe.yml
vendored
6
.github/workflows/abi-cafe.yml
vendored
@ -46,12 +46,12 @@ jobs:
|
|||||||
run: rustup set default-host x86_64-pc-windows-gnu
|
run: rustup set default-host x86_64-pc-windows-gnu
|
||||||
|
|
||||||
- name: Prepare dependencies
|
- name: Prepare dependencies
|
||||||
run: ./y.rs prepare
|
run: ./y.sh prepare
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: ./y.rs build --sysroot none
|
run: ./y.sh build --sysroot none
|
||||||
|
|
||||||
- name: Test abi-cafe
|
- name: Test abi-cafe
|
||||||
env:
|
env:
|
||||||
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
|
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
|
||||||
run: ./y.rs abi-cafe
|
run: ./y.sh abi-cafe
|
||||||
|
22
.github/workflows/main.yml
vendored
22
.github/workflows/main.yml
vendored
@ -19,7 +19,7 @@ jobs:
|
|||||||
- name: Rustfmt
|
- name: Rustfmt
|
||||||
run: |
|
run: |
|
||||||
cargo fmt --check
|
cargo fmt --check
|
||||||
rustfmt --check build_system/mod.rs
|
rustfmt --check build_system/main.rs
|
||||||
rustfmt --check example/*
|
rustfmt --check example/*
|
||||||
|
|
||||||
|
|
||||||
@ -91,15 +91,15 @@ jobs:
|
|||||||
sudo apt-get install -y gcc-s390x-linux-gnu qemu-user
|
sudo apt-get install -y gcc-s390x-linux-gnu qemu-user
|
||||||
|
|
||||||
- name: Prepare dependencies
|
- name: Prepare dependencies
|
||||||
run: ./y.rs prepare
|
run: ./y.sh prepare
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: ./y.rs build --sysroot none
|
run: ./y.sh build --sysroot none
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
env:
|
env:
|
||||||
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
|
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
|
||||||
run: ./y.rs test
|
run: ./y.sh test
|
||||||
|
|
||||||
- name: Install LLVM standard library
|
- name: Install LLVM standard library
|
||||||
run: rustup target add ${{ matrix.env.TARGET_TRIPLE }}
|
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'
|
if: matrix.os != 'windows-latest' || matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu'
|
||||||
env:
|
env:
|
||||||
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
|
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.
|
# 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
|
run: cargo install hyperfine || true
|
||||||
|
|
||||||
- name: Prepare dependencies
|
- name: Prepare dependencies
|
||||||
run: ./y.rs prepare
|
run: ./y.sh prepare
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: CI_OPT=1 ./y.rs build --sysroot none
|
run: CI_OPT=1 ./y.sh build --sysroot none
|
||||||
|
|
||||||
- name: Benchmark
|
- name: Benchmark
|
||||||
run: CI_OPT=1 ./y.rs bench
|
run: CI_OPT=1 ./y.sh bench
|
||||||
|
|
||||||
|
|
||||||
dist:
|
dist:
|
||||||
@ -224,13 +224,13 @@ jobs:
|
|||||||
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
|
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
|
||||||
|
|
||||||
- name: Prepare dependencies
|
- name: Prepare dependencies
|
||||||
run: ./y.rs prepare
|
run: ./y.sh prepare
|
||||||
|
|
||||||
- name: Build backend
|
- name: Build backend
|
||||||
run: CI_OPT=1 ./y.rs build --sysroot none
|
run: CI_OPT=1 ./y.sh build --sysroot none
|
||||||
|
|
||||||
- name: Build sysroot
|
- name: Build sysroot
|
||||||
run: CI_OPT=1 ./y.rs build
|
run: CI_OPT=1 ./y.sh build
|
||||||
|
|
||||||
- name: Package prebuilt cg_clif
|
- name: Package prebuilt cg_clif
|
||||||
run: tar cvfJ cg_clif.tar.xz dist
|
run: tar cvfJ cg_clif.tar.xz dist
|
||||||
|
4
.github/workflows/rustc.yml
vendored
4
.github/workflows/rustc.yml
vendored
@ -18,7 +18,7 @@ jobs:
|
|||||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
|
||||||
|
|
||||||
- name: Prepare dependencies
|
- name: Prepare dependencies
|
||||||
run: ./y.rs prepare
|
run: ./y.sh prepare
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: ./scripts/test_bootstrap.sh
|
run: ./scripts/test_bootstrap.sh
|
||||||
@ -38,7 +38,7 @@ jobs:
|
|||||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
|
||||||
|
|
||||||
- name: Prepare dependencies
|
- name: Prepare dependencies
|
||||||
run: ./y.rs prepare
|
run: ./y.sh prepare
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: ./scripts/test_rustc_tests.sh
|
run: ./scripts/test_rustc_tests.sh
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
/target
|
/target
|
||||||
|
/build_system/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
*.rlib
|
*.rlib
|
||||||
*.o
|
*.o
|
||||||
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -6,9 +6,10 @@
|
|||||||
"rust-analyzer.imports.granularity.enforce": true,
|
"rust-analyzer.imports.granularity.enforce": true,
|
||||||
"rust-analyzer.imports.granularity.group": "module",
|
"rust-analyzer.imports.granularity.group": "module",
|
||||||
"rust-analyzer.imports.prefix": "crate",
|
"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": [
|
"rust-analyzer.linkedProjects": [
|
||||||
"./Cargo.toml",
|
"./Cargo.toml",
|
||||||
|
"./build_system/Cargo.toml",
|
||||||
{
|
{
|
||||||
"crates": [
|
"crates": [
|
||||||
{
|
{
|
||||||
|
@ -3,13 +3,6 @@ name = "rustc_codegen_cranelift"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
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]
|
[lib]
|
||||||
crate-type = ["dylib"]
|
crate-type = ["dylib"]
|
||||||
|
|
||||||
@ -45,7 +38,6 @@ smallvec = "1.8.1"
|
|||||||
unstable-features = ["jit", "inline_asm"]
|
unstable-features = ["jit", "inline_asm"]
|
||||||
jit = ["cranelift-jit", "libloading"]
|
jit = ["cranelift-jit", "libloading"]
|
||||||
inline_asm = []
|
inline_asm = []
|
||||||
__check_build_system_using_ra = []
|
|
||||||
|
|
||||||
[package.metadata.rust-analyzer]
|
[package.metadata.rust-analyzer]
|
||||||
rustc_private = true
|
rustc_private = true
|
||||||
|
@ -10,8 +10,8 @@ If not please open an issue.
|
|||||||
```bash
|
```bash
|
||||||
$ git clone https://github.com/bjorn3/rustc_codegen_cranelift
|
$ git clone https://github.com/bjorn3/rustc_codegen_cranelift
|
||||||
$ cd rustc_codegen_cranelift
|
$ cd rustc_codegen_cranelift
|
||||||
$ ./y.rs prepare
|
$ ./y.sh prepare
|
||||||
$ ./y.rs build
|
$ ./y.sh build
|
||||||
```
|
```
|
||||||
|
|
||||||
To run the test suite replace the last command with:
|
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
|
$ ./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
|
## 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.
|
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:
|
In the directory with your project (where you can do the usual `cargo build`), run:
|
||||||
|
|
||||||
|
7
build_system/Cargo.lock
generated
Normal file
7
build_system/Cargo.lock
generated
Normal 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
13
build_system/Cargo.toml
Normal 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
|
@ -225,7 +225,7 @@ fn build_clif_sysroot_for_triple(
|
|||||||
match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) {
|
match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to get rustc version for patched sysroot source: {}", 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);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
Ok(source_version) => {
|
Ok(source_version) => {
|
||||||
@ -234,7 +234,7 @@ fn build_clif_sysroot_for_triple(
|
|||||||
eprintln!("The patched sysroot source is outdated");
|
eprintln!("The patched sysroot source is outdated");
|
||||||
eprintln!("Source version: {}", source_version.trim());
|
eprintln!("Source version: {}", source_version.trim());
|
||||||
eprintln!("Rustc version: {}", rustc_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);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
#![warn(rust_2018_idioms)]
|
||||||
|
#![warn(unused_lifetimes)]
|
||||||
|
#![warn(unreachable_pub)]
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process;
|
use std::process;
|
||||||
@ -37,19 +41,19 @@ enum Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub(crate) enum SysrootKind {
|
enum SysrootKind {
|
||||||
None,
|
None,
|
||||||
Clif,
|
Clif,
|
||||||
Llvm,
|
Llvm,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) enum CodegenBackend {
|
enum CodegenBackend {
|
||||||
Local(PathBuf),
|
Local(PathBuf),
|
||||||
Builtin(String),
|
Builtin(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn main() {
|
fn main() {
|
||||||
if env::var("RUST_BACKTRACE").is_err() {
|
if env::var("RUST_BACKTRACE").is_err() {
|
||||||
env::set_var("RUST_BACKTRACE", "1");
|
env::set_var("RUST_BACKTRACE", "1");
|
||||||
}
|
}
|
@ -1,11 +1,11 @@
|
|||||||
The build system of cg_clif.
|
The build system of cg_clif.
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
./y.rs prepare [--out-dir DIR] [--download-dir DIR]
|
./y.sh 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.sh 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.sh 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.sh 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 bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--debug
|
--debug
|
||||||
@ -40,7 +40,7 @@ REQUIREMENTS:
|
|||||||
* Rustup: By default rustup is used to install the right nightly version. If you don't want to
|
* 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
|
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.
|
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.
|
* 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.rs prepare` to download a single commit for
|
* 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.
|
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`.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
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
|
# 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
|
# FIXME remove at some point in the future
|
||||||
|
@ -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.
|
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
|
## Cargo
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ case $1 in
|
|||||||
|
|
||||||
./clean_all.sh
|
./clean_all.sh
|
||||||
|
|
||||||
./y.rs prepare
|
./y.sh prepare
|
||||||
|
|
||||||
(cd download/sysroot && cargo update && cargo fetch && cp Cargo.lock ../../build_sysroot/)
|
(cd download/sysroot && cargo update && cargo fetch && cp Cargo.lock ../../build_sysroot/)
|
||||||
;;
|
;;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
./y.rs build --no-unstable-features
|
./y.sh build --no-unstable-features
|
||||||
|
|
||||||
echo "[SETUP] Rust fork"
|
echo "[SETUP] Rust fork"
|
||||||
git clone https://github.com/rust-lang/rust.git || true
|
git clone https://github.com/rust-lang/rust.git || true
|
||||||
|
2
test.sh
2
test.sh
@ -1,2 +1,2 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
exec ./y.rs test "$@"
|
exec ./y.sh test "$@"
|
||||||
|
33
y.rs
33
y.rs
@ -1,35 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#![deny(unsafe_code)] /*This line is ignored by bash
|
#![deny(unsafe_code)] /*This line is ignored by bash
|
||||||
# This block is ignored by rustc
|
# This block is ignored by rustc
|
||||||
set -e
|
echo "Warning: y.rs is a deprecated alias for y.sh" 1>&2
|
||||||
echo "[BUILD] y.rs" 1>&2
|
exec ./y.sh "$@"
|
||||||
rustc $0 -o ${0/.rs/.bin} -Cdebuginfo=1 --edition 2021
|
|
||||||
exec ${0/.rs/.bin} $@
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#![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();
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user