File debian.rules of Package rust

#!/usr/bin/make -f
DEB_DISTRIBUTION := $(shell lsb_release -sc)
RUSTFLAGS = $(addprefix -C link-args=,$(LDFLAGS))
DEB_ARCH := $(shell dpkg --print-architecture)

include /usr/share/dpkg/architecture.mk

export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS RUSTFLAGS
export SHELL=/bin/bash

LLVM_ROOT := /usr

ifeq ($(DEB_DISTRIBUTION),$(filter $(DEB_DISTRIBUTION),stretch))
	LLVM_ROOT := /usr/lib/llvm-12
	export PATH := /usr/lib/llvm-12/bin/:$(PATH)
endif

ifeq ($(DEB_DISTRIBUTION),$(filter $(DEB_DISTRIBUTION),bullseye buster bionic focal))
	LLVM_ROOT := /usr/lib/llvm-15
	export PATH := /usr/lib/llvm-15/bin/:$(PATH)
endif

export AR := llvm-ar

ifeq ($(DEB_ARCH),armhf)
	HOST_RUST_TYPE := armv7-unknown-linux-gnueabihf
	codegen_units := --set rust.codegen-units=2
	debug_info := --disable-debuginfo --disable-debuginfo-only-std --disable-debuginfo-tools --disable-debuginfo-lines
else
	HOST_RUST_TYPE := x86_64-unknown-linux-gnu
	codegen_units := --set rust.codegen-units=0
	debug_info := --enable-debuginfo --disable-debuginfo-only-std --enable-debuginfo-tools --disable-debuginfo-lines
endif

export PROFILER := $(shell find $(LLVM_ROOT) -type f -name 'libclang_rt.profile-$(DEB_TARGET_GNU_CPU).a')


%:
	$(SYSTEM_WORKAROUNDS) dh $@ --parallel

override_dh_auto_test:
	echo "Skipping test"

override_dh_auto_configure:
	./rust-$(HOST_RUST_TYPE)/install.sh --components=cargo,rustc,rust-std-$(HOST_RUST_TYPE) --prefix=./usr --disable-ldconfig
	sed -i -e "1s|#!.*|#!/usr/bin/python3|" x.py
	sed -i.try-py3 -e '/try python2.7/i try python3 "$$@"' ./configure
	# We never enable emscripten.
	rm -rf src/llvm-emscripten/
	# We never enable other LLVM tools.
	rm -rf src/tools/clang
	rm -rf src/tools/lld
	rm -rf src/tools/lldb
	# CI tooling won't be used
	rm -rf src/stdsimd/ci
	# Remove hidden files from source
	find src/ -type f -name '.appveyor.yml' -exec rm -v '{}' '+'
	find src/ -type f -name '.travis.yml' -exec rm -v '{}' '+'

	rm -rf src/llvm/

	# The configure macro will modify some autoconf-related files, which upsets
	# cargo when it tries to verify checksums in those files.  If we just truncate
	# that file list, cargo won't have anything to complain about.
	find vendor -name .cargo-checksum.json -exec sed -i.uncheck -e 's/"files":{[^}]*}/"files":{ }/' '{}' '+'

	dh_auto_configure -- --disable-option-checking --build=$(HOST_RUST_TYPE) --host=$(HOST_RUST_TYPE) --enable-local-rust --local-rust-root=$(CURDIR)/usr --libdir=/usr/lib --docdir=/usr/share/doc/rust-doc --mandir=/usr/share/man --infodir=/usr/share/info --libexecdir=/usr/lib --prefix=/usr --llvm-root=$(LLVM_ROOT) --enable-llvm-link-shared --disable-codegen-tests --enable-optimize --enable-verbose-tests --disable-jemalloc --disable-rpath $(debug_info) $(codegen_units) --enable-vendor --enable-extended --tools=cargo,rustfmt --release-channel=stable --set target.$(HOST_RUST_TYPE).profiler=$(PROFILER)

	sed -i -e 's|#local-rebuild = false|local-rebuild = true|' config.toml

override_dh_auto_build:
	./x.py build -v

override_dh_auto_install:
	DESTDIR=$(CURDIR)/debian/rust ./x.py install
	# Remove installer artifacts (manifests, uninstall scripts, etc.)
	find $(CURDIR)/debian/rust/usr/lib/rustlib -maxdepth 1 -type f -exec rm -v '{}' '+'
	# The shared libraries should be executable for debuginfo extraction.
	find $(CURDIR)/debian/rust/usr/lib/rustlib -maxdepth 1 -type f -name '*.so' -exec chmod -v +x '{}' '+'

	# Move the bash-completition to correct directory
	mkdir -p debian/rust/usr/share/bash-completion/completions/
	mv debian/rust/etc/bash_completion.d/cargo debian/rust/usr/share/bash-completion/completions/
	rm -rf debian/rust/etc

	mkdir -p debian/rust/usr/lib/$(DEB_HOST_MULTIARCH)/
	mv debian/rust/usr/lib/lib*.so debian/rust/usr/lib/$(DEB_HOST_MULTIARCH)/

	# Replace duplicated compile-time/run-time dylibs with symlinks
	@set -e; \
	for f in $(CURDIR)/debian/rust/usr/lib/rustlib/$(HOST_RUST_TYPE)/lib/lib*.so; do \
	  name=$${f##*/}; \
	  if [ -f "$(CURDIR)/debian/rust/usr/lib/$(DEB_HOST_MULTIARCH)/$$name" ]; then \
	    echo "ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f"; \
	    ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f; \
	  fi; \
	done

override_dh_shlibdeps:
	dh_shlibdeps -- -x$(DEB_HOST_MULTIARCH)
openSUSE Build Service is sponsored by