rust-embedded / discovery

Discover the world of microcontrollers through Rust!
https://docs.rust-embedded.org/discovery/
Apache License 2.0
1.49k stars 515 forks source link

Building on f3discovery root directory #501

Closed pat0026 closed 1 year ago

pat0026 commented 1 year ago

I have read the following note:

NOTE Make sure you are in the src/05-led-roulette directory and run cargo build command below to create the executable

But I was trying to build led-roulette on the f3discovery root directory by utilizing the package parameter with the following command:

cargo build -p "led-roulette" --target thumbv7em-none-eabihf --verbose

I noticed that the -C link-arg=-Tlink.x wasn't added to the options in the build command even though it is already on the discovery/f3discovery/src/.cargo/config.toml.

Built on discovery/f3discovery (no -C link-arg=-Tlink.x):

Running rustc --crate-name led_roulette --edition=2018 src\05-led-roulette\src\main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=7d72679e334c868e -C extra-filename=-7d72679e334c868e --out-dir C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\deps --target thumbv7em-none-eabihf -C incremental=C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\incremental -L dependency=C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\deps -L dependency=C:\Exploration\repo\github\discovery\f3discovery\target\debug\deps --extern aux5=C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\deps\libaux5-dfde45e794eed34e.rlib -L C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\build\cortex-m-59c645a98028bcaf\out -L C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\build\cortex-m-rt-7e28cab60c2b1714\out -L C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\build\stm32f3-discovery-d720e4e7f63df0be\out -L C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\build\stm32f3-c8f3c2ed2f4bb62e\out

Built on discovery/f3discovery/src/05-led-roulette (has -C link-arg=-Tlink.x):

Running rustc --crate-name led_roulette --edition=2018 src\05-led-roulette\src\main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=7d72679e334c868e -C extra-filename=-7d72679e334c868e --out-dir C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\deps --target thumbv7em-none-eabihf -C incremental=C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\incremental -L dependency=C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\deps -L dependency=C:\Exploration\repo\github\discovery\f3discovery\target\debug\deps --extern aux5=C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\deps\libaux5-dfde45e794eed34e.rlib -C link-arg=-Tlink.x -L C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\build\cortex-m-59c645a98028bcaf\out -L C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\build\cortex-m-rt-7e28cab60c2b1714\out -L C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\build\stm32f3-discovery-d720e4e7f63df0be\out -L C:\Exploration\repo\github\discovery\f3discovery\target\thumbv7em-none-eabihf\debug\build\stm32f3-c8f3c2ed2f4bb62e\out

I would like to know the reason why this is and how to build on the root directory with different members like f3discovery. I might try to organize my personal project that is closely related to each other in this way on my embedded journey. Or is this a limitation of the cargo build?

pat0026 commented 1 year ago

I found the answer to my question and would like to share it here. I needed to move the .cargo directory under src to the root directory. From ./src/.cargo to ./.cargo.

Please see the following documentation as a reference: hierarchical-structure