diff --git a/.github/workflows/test_pallet_patcher.yml b/.github/workflows/test_pallet_patcher.yml new file mode 100644 index 0000000..c8029f8 --- /dev/null +++ b/.github/workflows/test_pallet_patcher.yml @@ -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 diff --git a/colcon_cargo/task/cargo/build.py b/colcon_cargo/task/cargo/build.py index 3a7557e..b3a9c54 100644 --- a/colcon_cargo/task/cargo/build.py +++ b/colcon_cargo/task/cargo/build.py @@ -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__) @@ -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) @@ -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 diff --git a/setup.cfg b/setup.cfg index 93bfa8f..bf9b4d3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/test/pallet_patcher_ws/hello_world/Cargo.toml b/test/pallet_patcher_ws/hello_world/Cargo.toml new file mode 100644 index 0000000..4f0a461 --- /dev/null +++ b/test/pallet_patcher_ws/hello_world/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "hello_world" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/test/pallet_patcher_ws/hello_world/src/main.rs b/test/pallet_patcher_ws/hello_world/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/test/pallet_patcher_ws/hello_world/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/test/pallet_patcher_ws/hello_world2/Cargo.toml b/test/pallet_patcher_ws/hello_world2/Cargo.toml new file mode 100644 index 0000000..1c7ab29 --- /dev/null +++ b/test/pallet_patcher_ws/hello_world2/Cargo.toml @@ -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" diff --git a/test/pallet_patcher_ws/hello_world2/src/main.rs b/test/pallet_patcher_ws/hello_world2/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/test/pallet_patcher_ws/hello_world2/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}