summaryrefslogtreecommitdiff
path: root/debian/rules
blob: 459ac10c74d8fde11636570bd566343c94fc5b32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/make -f
include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/buildflags.mk
include /usr/share/rustc/architecture.mk
export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
export DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE
export CARGO_PROFILE_RELEASE_DEBUG=true
export LIBSTDBUF_DIR = /usr/libexec/rust-coreutils
VERSION := $(shell dpkg-parsechangelog -S Version|sed -e "s|.*~\(.*\)-.*|\1|g")
UPSTREAM_VERSION := $(shell dpkg-parsechangelog -S Version|cut -d- -f1)

# Build a multicall binary instead of multiple binaries
# to reduce the storage footprint
export MULTICALL = y

# Vendoring setup
# FIXME: The upstream Makefile we use doesn't work with the cargo wrapper,
# as it assumes no cross-compilation and hence files appearing in target/release
# rather than the architecture-specific target directory.
#export CARGO = /usr/share/cargo/bin/cargo
export CARGO_VENDOR_DIR = rust-vendor
export CARGO_HOME = $(CURDIR)/debian/cargo_home

# Build verbosely
export CARGOFLAGS = -v

VENDOR_TARBALL = rust-coreutils_$(UPSTREAM_VERSION).orig-$(CARGO_VENDOR_DIR).tar.xz

%:
	dh $@ --buildsystem cargo

vendor-tarball-quick-check:
	if [ -e ../$(VENDOR_TARBALL) ]; then echo "../$(VENDOR_TARBALL) already exists, bailing!"; exit 1; fi

vendor-deps-cargo:
	rm -rf $(CARGO_VENDOR_DIR)
	# Deliberately don't use the wrapper, as it expects the configure step
	# to have occurred already.
	# If you have to modify the path here, don't forget to change the README.source doc
	# as well.
	env -i cargo-vendor-filterer --all-features  --tier 2  --platform '*-*-linux-gnu' --platform '*-*-linux-gnueabi' $(CARGO_VENDOR_DIR)

vendor-deps: vendor-deps-cargo
	rm -r \
		$(CARGO_VENDOR_DIR)/*/tests
	# Remove the checksum files to allow us to patch the crates to remove extraneous dependencies
	for crate in $(CARGO_VENDOR_DIR)/*; do \
		sed -i 's/^{"files":.*"package":"\([a-z0-9]\+\)"}$$/{"files":{},"package":"\1"}/' $$crate/.cargo-checksum.json; \
		done
	# Cleanup temp files
	rm -rf $(CARGO_HOME)

vendor-tarball: vendor-tarball-quick-check vendor-deps
	tar --sort=name --mtime=@0 --owner=0 --group=0 --numeric-owner --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime -caf ../$(VENDOR_TARBALL) $(CARGO_VENDOR_DIR)

override_dh_auto_configure:
	CARGO_HOME=$(CURDIR)/debian/cargo_home DEB_CARGO_CRATE=coreutils_$(VERSION) /usr/share/cargo/bin/cargo prepare-debian $(CARGO_VENDOR_DIR)
	/usr/share/cargo/bin/dh-cargo-vendored-sources
	dh_auto_configure

override_dh_auto_test:
	CARGO_HOME=$(CURDIR)/debian/cargo_home make PROFILE=release MULTICALL=$(MULTICALL) \
				TEST_NO_FAIL_FAST="-- --skip test_env::test_env_arg_ignore_signal_valid_signals \
				--skip test_env::test_simulation_of_terminal_for_stdin_only \
				--skip test_simulation_of_terminal_size_information \
				--skip test_simulation_of_terminal_true \
				--skip test_expr::test_long_input \
				--skip test_factor::test_parallel \
				--skip test_chown::test_chown_only_group_id_nonexistent_group \
				--skip test_chown::test_chown_only_user_id_nonexistent_user \
				--skip test_install::test_install_and_strip \
				--skip test_install::test_install_and_strip_with_program \
				--skip test_install::test_install_root_combined \
				--skip test_od::test_od_options_after_filename \
				--skip test_od::test_suppress_duplicates \
				--skip test_pinky::test_no_flag \
				--skip test_pinky::test_short_format_i \
				--skip test_pinky::test_short_format_q \
				--skip test_stat::test_fs_format \
				--skip test_stat::test_mount_point_basic \
				--skip test_stat::test_mount_point_combined_with_other_specifiers \
				--skip test_stat::test_multi_files \
				--skip test_stat::test_normal_format \
				--skip test_stat::test_printf \
				--skip test_stat::test_symlinks \
				--skip test_stat::test_terse_fs_format \
				--skip test_stdbuf::test_libstdbuf_preload \
				--skip test_stdbuf::test_no_such \
				--skip test_stdbuf::test_permission \
				--skip test_stdbuf::test_stdbuf_line_buffered_stdout \
				--skip test_stdbuf::test_stdbuf_non_utf8_paths \
				--skip test_stdbuf::test_stdbuf_trailing_var_arg \
				--skip test_stdbuf::test_stdbuf_unbuffered_stdout \
				--skip test_who::test_boot \
				--skip util_invalid_name_invalid_command" \
				test

override_dh_auto_install:
#use thin rather than full lto on 32-bit to avoid running out of address space.
ifeq ($(DEB_HOST_ARCH_BITS),32)
	sed -i 's/lto = true/lto = "thin"/' Cargo.toml
endif
	CARGO_HOME=$(CURDIR)/debian/cargo_home DESTDIR=$(CURDIR)/debian/tmp/ make SELINUX_ENABLED=1 PROFILE=release MULTICALL=$(MULTICALL) install
ifeq ($(DEB_HOST_ARCH_BITS),32)
	sed -i 's/lto = "thin"/lto = true/' Cargo.toml
endif
# Create the symlink early to be able to generate the manpages
	cd debian/tmp/usr/share/zsh/site-functions && mkdir rust-coreutils && chmod -x _* && mv _* rust-coreutils
	cd debian/tmp/usr/share/bash-completion/completions/ && chmod -x rust-*
	cd debian/tmp/usr/share/fish/vendor_completions.d/ && chmod -x *.fish
	cd debian/tmp/usr/bin && mv rust-coreutils coreutils && rm rust-*
#	cd debian/tmp/usr/share/fish/vendor_completions.d && for f in *fish; do mv $$f rust-$$f; done
#
execute_after_dh_install:
	install -d debian/rust-coreutils/usr/lib/cargo/bin/coreutils
	cat debian/rust-coreutils.hardlinks | while read a b; do \
		env -C debian/rust-coreutils/ ln $$a $$b; \
	done

override_dh_missing:
	dh_missing --fail-missing

override_dh_dwz:
	# Don't do anything. fails because of the
	# https://github.com/rust-lang/rust/issues/66118

#use lower debuginfo level on 32-bit to avoid running out of address space.
ifeq ($(DEB_HOST_ARCH_BITS),32)
execute_after_dh_auto_configure:
	if test -f debian/cargo_home/config; then \
		sed -i s/debuginfo=2/debuginfo=1/ debian/cargo_home/config; \
	fi
endif

override_dh_clean:
	rm -f Cargo.toml.orig Cargo.lock
	dh_clean