Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/test_pallet_patcher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Test automatic selection of deps

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:
name: Build & Test
runs-on: ubuntu-24.04

steps:

# Code of this repo
- name: Checkout this repo
uses: actions/checkout@v4
with:
path: root

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install pallet-patcher from dev branch
run: |
pip install git+https://github.com/cottsay/pallet-patcher.git@blast545/smarter_pallet_patcher
pallet-patcher -h

- name: Install colcon-cargo from this branch
run: |
cd $GITHUB_WORKSPACE/root
pip install .
pip install colcon-common-extensions
pip freeze

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install some Rust system crates
run: |
sudo apt-get install librust-serde-dev librust-tokio-dev librust-crc32fast-dev
dpkg -L librust-tokio-dev

- name: Install tokio crate as part of example
run: |
cargo install cargo-download
cd $GITHUB_WORKSPACE/root/test/pallet_patcher_ws/
mkdir -p ./deps
cd deps/
cargo download tokio > tokio.gz
tar -xvf tokio.gz -C ./
rm tokio.gz

- name: Test pallet-patcher alone before checking colcon-cargo integration
run: |
pallet-patcher --output-format toml $GITHUB_WORKSPACE/root/test/pallet_patcher_ws/deps/tokio-1.49.0/Cargo.toml $GITHUB_WORKSPACE/root/test/pallet_patcher_ws/deps

- name: colcon build example project with a tokio crate available in workspace_ws/deps
run: |
ls $GITHUB_WORKSPACE/root/
cd $GITHUB_WORKSPACE/root/test/pallet_patcher_ws/
ls
colcon --log-level debug build --event-handlers console_direct+

- name: Take a look to our Cargo.lock file for hello_world2
run: |
ls $GITHUB_WORKSPACE/root/test/pallet_patcher_ws/
ls $GITHUB_WORKSPACE/root/test/pallet_patcher_ws/hello_world2/
cat $GITHUB_WORKSPACE/root/test/pallet_patcher_ws/hello_world2/Cargo.lock
25 changes: 24 additions & 1 deletion colcon_cargo/task/cargo/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from colcon_core.task import run
from colcon_core.task import TaskExtensionPoint

from pallet_patcher.command import load_and_compose
from pallet_patcher.search import get_cargo_arguments

logger = colcon_logger.getChild(__name__)


Expand Down Expand Up @@ -71,9 +74,28 @@ async def build( # noqa: D102
# Get package metadata
metadata = await self._get_metadata(env)

###### Run pallet-patcher to fetch anything available in colcon's workspace
###### or in our system dependencies:
base_path = Path(args.path)

# TO-DO: How I get this to be the path where colcon is being run? workspace root
if "/deps" in str(base_path.parent):
ws_crates_paths = [base_path.parent.parent / Path("deps")]
else:
ws_crates_paths = [base_path.parent / Path("deps")]

system_crates_paths = [Path("/usr/share/cargo/registry/")]
manifest_path = base_path / Path("Cargo.toml")
logger.info("Searching for local crates in '{ws_crates_paths}'".format_map(locals()))
logger.info("Searching for system crates in '{system_crates_paths}'".format_map(locals()))
logger.info("Searching for metadata in '{manifest_path}'".format_map(locals()))
composition = load_and_compose(manifest_path, ws_crates_paths, system_crates_paths)
crates_available_locally = get_cargo_arguments(composition)
logger.info("Extra crates:" + str(crates_available_locally))

cargo_args = args.cargo_args
if cargo_args is None:
cargo_args = []
cargo_args = [] + crates_available_locally
# Invoke build step
cmd = self._build_cmd(cargo_args)

Expand Down Expand Up @@ -125,6 +147,7 @@ def _build_cmd(self, cargo_args):
for arg in cargo_args
):
cmd += ['--profile', 'dev']
logger.info(f"Build command: {cmd} and arguments: {cargo_args}")
return cmd + cargo_args

# Overridden by colcon-ros-cargo
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ install_requires =
colcon-core>=0.19.0
# toml is also supported but deprecated
tomli>=1.0.0; python_version < "3.11"
pallet_patcher>=0.0.2
packages = find:
zip_safe = true

Expand Down
6 changes: 6 additions & 0 deletions test/pallet_patcher_ws/hello_world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "hello_world"
version = "0.1.0"
edition = "2024"

[dependencies]
3 changes: 3 additions & 0 deletions test/pallet_patcher_ws/hello_world/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
9 changes: 9 additions & 0 deletions test/pallet_patcher_ws/hello_world2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "hello_world2"
version = "0.1.0"
edition = "2024"

[dependencies]
crc32fast = "1.3"
tokio = { version = "1.0", features = ["full"] }
serde = "1.0"
3 changes: 3 additions & 0 deletions test/pallet_patcher_ws/hello_world2/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}