distributable:
  url: https://static.rust-lang.org/dist/rustc-{{ version }}-src.tar.gz
  strip-components: 1

versions:
  github: rust-lang/rust
  strip: /^Rust /

companions:
  rust-lang.org/cargo: '*'

display-name: rust

provides:
  - bin/cargo-clippy
  - bin/cargo-fmt
  - bin/clippy-driver
  - bin/rust-analyzer
  - bin/rust-gdb
  - bin/rust-gdbgui
  - bin/rust-lldb
  - bin/rustc
  - bin/rustdoc
  - bin/rustfmt

#TODO: unimplemented idea for the “options” feature
options:
  - clippy
  - rustfmt
  - analysis
  - { name: rust-demangler, default: false }

dependencies:
  linux:
    llvm.org: '*'
  #FIXME ^^ strictly rustc only needs a linker
  zlib.net: 1

build:
  dependencies:
    cmake.org: ^3.20
    ninja-build.org: ^1.10
    python.org: '>=3<3.12'
    openssl.org: '*' # needed to build openssl-sys
    freedesktop.org/pkg-config: ^0.29
    crates.io/semverator: 0
    linux:
      gnu.org/make: '*'
  script:
    # --enable-optimize not available as of 1.63.0
    - run: export ARGS="$ARGS --enable-optimize"
      if: <1.63.0

    # 1.68.0 introduced a regression w.r.t. CI builds
    # https://github.com/rust-lang/rust/issues/108959
    - run: |
        sed -i.bak -e 's/CiEnv::is_ci()/CiEnv::is_ci() \&\& config.rust_info.is_managed_git_subrepository()/' native.rs
        rm native.rs.bak
      if: '>=1.68<1.70'
      working-directory: src/bootstrap

    - ./configure $ARGS
    - make install

    - |
      for tool in $tools; do
        ./x.py install $tool
      done

    - rm -rf {{prefix}}/share/doc
  env:
    ARGS:
      - --enable-vendor
      - --prefix={{ prefix }}
      - --enable-ninja
      - --disable-docs # docs are online
      - --tools=clippy,rustdoc,rustfmt,analysis
      - --sysconfdir={{ prefix }}/etc
    tools:
      - clippy
      - rustfmt
      - rust-analyzer

test:
  script: |
    mv $FIXTURE hello.rs
    rustc hello.rs
    ./hello
  fixture: |
    fn main() {
      println!("Hello World!");
    }
