-
Notifications
You must be signed in to change notification settings - Fork 4
Fix clash with new esp generate template #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a5f0857
Change link section of metadata in order to embed into rodata
petekubiak eaab37d
Remove redundant linker script
petekubiak 3d43f7c
Update README to reflect changes
petekubiak 73a5df7
Bump version to 0.2.0
petekubiak e438922
Update template build script
petekubiak 749e4dc
Add missing instruction in init.rhai
petekubiak 8364510
[MegaLinter] Apply linters automatic fixes (#38)
github-actions[bot] 1012fe1
Fix init.rhai error
petekubiak 8c2e68b
Add build dependency to template
petekubiak 6bc3754
Switch to one-line invocation in template
petekubiak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,13 @@ Navigate into your project directory and add the crate to your dependencies with | |
| cargo add --git https://github.com/dysonltd/commitment-issues | ||
| ``` | ||
|
|
||
| This crate makes use of code run at compile time through the `build.rs` script. | ||
| As such, you will also need to add the crate as a build dependency with: | ||
|
|
||
| ```sh | ||
| cargo add --build --git https://github.com/dysonltd/commitment-issues | ||
| ``` | ||
|
|
||
| #### Configure the project to include the metadata in the binary | ||
|
|
||
| Run `cargo generate` with the following command and follow the prompts: | ||
|
|
@@ -67,24 +74,22 @@ cargo generate -g https://github.com/dysonltd/commitment-issues --init | |
|
|
||
| **Please note** the `--init` argument being passed to `cargo generate`. This specifies that the target project already exists. | ||
|
|
||
| If certain files already exist in your project, you will need to add commands to them to complete the configuration. | ||
| If certain files already exist in your project, you will need to manually add commands to them to complete the configuration. | ||
| Make sure to follow all the prompts given during the `cargo generate` process. | ||
|
|
||
| #### Invoke metadata embedding | ||
|
|
||
| Add the following to one of your project's source files (e.g. `src/main.rs`): | ||
|
|
||
| ```rust | ||
| use commitment_issues::include_metadata; | ||
|
|
||
| include_metadata!(); | ||
| commitment_issues::include_metadata!(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the template generated by cargo generate use this oneline version too? i.e. template/src/main.rs |
||
| ``` | ||
|
|
||
| This invokes the `include_metadata!()` macro, which generates a module called `metadata` within your source file at compile time. | ||
|
|
||
| #### Accessing metadata within project source code | ||
|
|
||
| As well as containing the metadata section, the `metadata` module exposes a set of macros to access the various fields of the metadata section from within your code. | ||
| As well as containing the metadata, the `metadata` module exposes a set of macros to access the various fields of the metadata section from within your code. | ||
| The template's [main.rs](https://github.com/dysonltd/commitment-issues/blob/main/template/src/main.rs) file gives an example of how these macros can be used. | ||
|
|
||
| #### Standard Compile and run | ||
|
|
@@ -100,13 +105,6 @@ If you see issues relating to being unable to find openssl headers, try activati | |
|
|
||
| ## Inspecting binary metadata | ||
|
|
||
| The metadata can be found in a section called ".metadata" within the executable binary generated by cargo. | ||
| <!-- markdown-link-check-disable-line --> This can easily be read using `objdump` from the [`binutils`](https://www.gnu.org/software/binutils/) package: | ||
|
|
||
| ```sh | ||
| objdump -s <path/to/binary> | grep "section \.metadata" -A 20 | ||
| ``` | ||
|
|
||
| The metadata is an 80-byte block beginning with the sequence 0xFFFEFDFC and ending with the sequence 0x01020304 (inclusive). | ||
| The data contained within is as follows: | ||
|
|
||
|
|
@@ -124,6 +122,43 @@ Future work will include adding a command line tool for reading metadata from a | |
| The current structure of the metadata is fixed. | ||
| Future work will aim to make it possible to configure the structure of the metadata through a configuration file. | ||
|
|
||
| The metadata is embedded into the binary's read-only data section, generally named `.rodata`. | ||
| Mac binaries instead store read-only data in `__DATA,__const`. | ||
|
|
||
| The easiest way to inspect the metadata within the binary is using the `objdump` tool from `binutils`. | ||
| The `cargo-binutils` package provides cargo integration of these tools. | ||
| First install the tools themselves with: | ||
|
|
||
| ```sh | ||
| rustup component add llvm-tools | ||
| ``` | ||
|
|
||
| Then the cargo integration can be installed either as precompiled binaries: | ||
|
|
||
| ```sh | ||
| cargo binstall cargo-binutils | ||
| ``` | ||
|
|
||
| or from source with: | ||
|
|
||
| ```sh | ||
| cargo install cargo-binutils | ||
| ``` | ||
|
|
||
| The binary metadata can now be inspected with: | ||
|
|
||
| ```sh | ||
| cargo objdump -s -j .rodata | ||
| ``` | ||
|
|
||
| *NOTE* For Mac binaries, replace `.rodata` with `__DATA,__const`. | ||
|
|
||
| If your read-only data section is very long, it may be easier to find the metadata with grep by looking for the header: | ||
|
|
||
| ```sh | ||
| cargo objdump -s -j .rodata | grep "fffefdfc" -A 20 | ||
| ``` | ||
|
|
||
| ## Windows targets | ||
|
|
||
| **TODO!** This crate has not yet been tested for a Windows target. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| fn main() { | ||
| println!("cargo:rerun-if-changed=./.git/"); | ||
| println!("cargo:rustc-link-arg=-Tmetadata.x"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the template to have this too