python/pydantic_core: update to 2.27.0
[oi-userland.git] / make-rules / cargo.mk
blob40ff797acecdd19528094db823427e23519a985b
2 # This file and its contents are supplied under the terms of the
3 # Common Development and Distribution License ("CDDL"), version 1.0.
4 # You may only use this file in accordance with the terms of version
5 # 1.0 of the CDDL.
7 # A full copy of the text of the CDDL should have accompanied this
8 # source. A copy of the CDDL is also available via the Internet at
9 # http://www.illumos.org/license/CDDL.
13 # Copyright 2024 Marcel Telka
17 # cargo build style
19 # Cargo is the Rust package manager used to download, compile, and install Rust
20 # packages and their dependencies.
23 # Common Cargo home used as a cache for downloaded crates
24 CARGO_ARCHIVES ?= $(USERLAND_ARCHIVES)/.cargo
26 # The full path to the cargo binary. It lives in the rustc package.
27 CARGO = /usr/bin/cargo
28 USERLAND_REQUIRED_PACKAGES += developer/lang/rustc
30 # Fetch all dependencies and vendor them locally
31 CARGO_VENDOR_DIR = $(BUILD_DIR)/cargo-vendor
32 COMPONENT_PREP_ACTION += [ -f $(SOURCE_DIR)/Cargo.toml ] || exit 1 ;
33 COMPONENT_PREP_ACTION += $(ENV) CARGO_HOME=$(CARGO_ARCHIVES) \
34 $(CARGO) fetch --manifest-path $(SOURCE_DIR)/Cargo.toml || exit 1 ;
35 COMPONENT_PREP_ACTION += $(MKDIR) $(SOURCE_DIR)/.cargo ;
36 COMPONENT_PREP_ACTION += $(ENV) CARGO_HOME=$(CARGO_ARCHIVES) \
37 $(CARGO) vendor --manifest-path $(SOURCE_DIR)/Cargo.toml \
38 --versioned-dirs --offline $(CARGO_VENDOR_DIR) \
39 | $(TEE) $(SOURCE_DIR)/.cargo/config.toml ;
41 # Common cargo environment
42 CARGO_ENV += CARGO_HOME=$(@D)/.cargo
43 CARGO_ENV += PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)"
45 # Some tests fails with the default symlink cloney mode
46 CLONEY_MODE = copy
48 # Build
49 COMPONENT_BUILD_CMD = $(CARGO) build
50 COMPONENT_BUILD_ARGS += --release
51 COMPONENT_BUILD_ARGS += --offline
52 COMPONENT_BUILD_ENV += $(CARGO_ENV)
54 # https://www.illumos.org/issues/15767
55 LD_Z_IGNORE=
57 # Install
58 COMPONENT_INSTALL_CMD = $(CARGO) install
59 COMPONENT_INSTALL_ARGS += --path .
60 COMPONENT_INSTALL_ARGS += --root $(PROTOUSRDIR)
61 COMPONENT_INSTALL_ARGS += --force
62 COMPONENT_INSTALL_ARGS += --no-track
63 COMPONENT_INSTALL_ARGS += --offline
64 COMPONENT_INSTALL_ARGS += --locked
65 COMPONENT_INSTALL_ENV += $(CARGO_ENV)
67 # Test
68 COMPONENT_TEST_CMD = $(CARGO) test
69 COMPONENT_TEST_ARGS += --release
70 COMPONENT_TEST_ARGS += --offline
71 COMPONENT_TEST_TARGETS =
72 COMPONENT_TEST_ENV += $(CARGO_ENV)
74 # drop header
75 COMPONENT_TEST_TRANSFORMS += "-e '0,/Finished/d'"
76 # remove timing
77 COMPONENT_TEST_TRANSFORMS += "-e 's/\(finished\) in [0-9]\{1,\}\.[0-9]\{2\}s\$$/\1/g'"
78 # sort tests
79 COMPONENT_TEST_TRANSFORMS += "| ( while true ; do \
80 $(GSED) -u -e '/^running [0-9]\{1,\} tests\$$/q1' && break ; \
81 $(GSED) -u -e '/^\$$/Q' | $(SORT) ; \
82 echo "" ; \
83 done ) | $(COMPONENT_TEST_TRANSFORMER) -e ''"
85 # Cleanup
86 clean::
87 $(RM) -r $(SOURCE_DIR) $(BUILD_DIR)
89 # Use common rules
90 USE_COMMON_RULES = yes