Skip to content

Commit ef7231e

Browse files
author
Amanjeev Sethi
authored
Merge pull request #2 from ferrous-systems/amanjeev/improvements
Improvements, format flow, sections on new projects
2 parents 2651212 + 536f732 commit ef7231e

File tree

1 file changed

+94
-40
lines changed

1 file changed

+94
-40
lines changed

README.md

Lines changed: 94 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Demo: Ferrocene and its toolchain within GitHub Action(s)
22

3-
This is a very simple demo.
3+
This is a simplified demo.
44

55
## Prerequisites
66

@@ -10,11 +10,20 @@ This is a very simple demo.
1010

1111
## Steps to use Ferrocene in your project
1212

13-
Note: This section will assume that you have access to GitHub and already have a Rust project you want to use Ferrocene for.
13+
### Create a new project directory
1414

15-
### Add a project manifest to your repo
15+
We will create a brand new project that works with Ferrocene.
16+
Create a directory where you will have your project files and `cd` into it.
1617

17-
Ferrocene comes with its own toolchain and toolchain manager. Main tool is called [CriticalUp], which is Ferrocene's toolchain manager.
18+
```sh
19+
mkdir ferrocene-demo
20+
cd ferrocene-demo
21+
```
22+
23+
### Add the Ferrocene project manifest to `ferrocene-demo` directory
24+
25+
Ferrocene comes with its own toolchain and toolchain manager. The main tool is called
26+
[CriticalUp], which is Ferrocene's toolchain manager.
1827

1928
Create a file in project root: `criticalup.toml` and paste the following content in it:
2029

@@ -32,62 +41,43 @@ packages = [
3241

3342
Some highlights about CriticalUp and the project manifest:
3443

35-
- This is CritalUp project manifest file. It is usually named `criticalup.toml`. CriticalUp tries to find it within your project folder or its parent directory.
36-
- You can override this and provide an explicit `--project` flag with path to your own `criticalup.toml` file for your project.
44+
- This is the CriticalUp project manifest file. It is usually named `criticalup.toml`.
45+
CriticalUp tries to find it within your project folder or its parent directory.
46+
- You can override this and provide an explicit `--project` flag with a path to your `criticalup.toml` file for your project.
3747
- `criticalup install --project /path/to/my/manifest/criticalup.toml`.
3848
- Used to install Ferrocene and its releases for your project, and packages and dependencies for the release (like [rustup]).
3949
- Also used to build/run your project (like [cargo]).
4050
- You can use `-${rustc-host}` suffix to automatically have CriticalUp fill the current architecture triple.
4151

42-
### Get the CriticalUp Token to authenticate
52+
### Get the CriticalUp Token to authenticate: get your token
4353

4454
- To install any Ferrocene product/toolchain, you will need to get a token from the [Ferrocene Customer Portal].
4555
This token can be created in your account.
4656
- The tokens are at the [Ferrocene CriticalUp Tokens] section of the portal.
4757
- Once you are on the page, click "New Token", provide a memorable title for it, and once generated copy the token.
4858
- The token is only shown once for security.
4959

50-
### Add the CriticalUp Token to GitHub Action secrets
51-
52-
The CriticalUp Token you got from the [Ferrocene Customer Portal] must be set in your GitHub repo's Settings.
53-
54-
- Go to 'Settings' tab of your GitHub repo.
55-
- Click 'Secrets and variables'.
56-
- Click 'Actions'.
57-
- Click 'New repository secret'.
58-
- Add Name as `CRITICALUP_TOKEN` and past the token from [Ferrocene Customer Portal] in the 'Secret' text area.
59-
60-
### Create a simple GitHub Action
61-
62-
An example of a fully working Github CI workflow file can be found in the workflow file [`build.yml`] of this demo project.
63-
64-
- When no workflow file in your project exists, copy the `build.yml` into the folder `.github/workflows`, otherwise
65-
copy the CI job `install-criticalup-build-run-my-app` into your existing workflow file.
66-
- Adapt the workflow if necessary, for example to compile the project instead of run it.
67-
- We will use a single job so we don't need to cache anything. The job consists of multiple steps.
68-
- We will showcase only Ubuntu 20.04 in this exercise.
69-
70-
#### Install CriticalUp
60+
### Install CriticalUp
7161

7262
The [Installing CriticalUp](https://criticalup.ferrocene.dev/install.html) section of the [Criticalup documentation] says to run:
7363

7464
```shell
7565
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/ferrocene/criticalup/releases/latest/download/criticalup-installer.sh | sh
7666
```
7767

78-
> See the step 'Make sure CriticalUp is installed and available' in [`build.yml`].
68+
> For GitHub Actions: See the step 'Make sure CriticalUp is installed and available' in [`build.yml`].
7969
80-
#### Test CriticalUp is installed
70+
### Test CriticalUp is installed
8171

8272
The following command does not require a token or authentication and can tell you available subcommands for CriticalUp.
8373

8474
```shell
8575
criticalup --help
8676
```
8777

88-
> See the step 'Test if CriticalUp is installed' in [`build.yml`].
78+
> For GitHub Actions: See the step 'Test if CriticalUp is installed' in [`build.yml`].
8979
90-
#### Authenticate CriticalUp
80+
### Authenticate CriticalUp
9181

9282
**This section assumes you have done the following from above:**
9383

@@ -100,33 +90,97 @@ In your GitHub Action you can use the secret now as:
10090
criticalup auth set ${{ secrets.CRITICALUP_TOKEN }}
10191
```
10292

103-
> See the step 'Authenticate CriticalUp' in [`build.yml`].
93+
> For GitHub Actions: See the step 'Authenticate CriticalUp' in [`build.yml`].
10494
105-
#### Install Ferrocene toolchain
95+
### Install Ferrocene toolchain
10696

10797
**This step assumes you have already done the following from above:**
10898

10999
- Add a project manifest to your repo
110100

111-
Just running the following command will install the toolchain listed in your project manifest (`criticalup.toml`).
101+
Running the following command will install the toolchain listed in your project manifest (`criticalup.toml`).
112102

113103
```shell
114104
criticalup install
115105
```
116106

117-
> See the step 'Install Ferrocene toolchain from the project manifest (criticalup.toml)' in [`build.yml`].
107+
> For GitHub Actions: See the step 'Install Ferrocene toolchain from the project manifest (criticalup.toml)' in [`build.yml`].
108+
109+
### Create new binary project
110+
111+
Once the toolchain is installed, you will have `rustc`, `cargo`, and `rust-std` available in the toolchain.
112+
113+
We will run a command to create a new binary project:
114+
115+
```sh
116+
criticalup run cargo init
117+
```
118+
119+
or explicitly passing `--project` manifest:
120+
121+
```sh
122+
criticalup run --project criticalup.toml cargo init
123+
```
124+
125+
This will initialize a new project in the directory `ferrocene-demo`.
126+
Note how we pass `cargo init` to the `criticalup run` command.
127+
128+
### Alternatively create new embedded project
129+
130+
**Note:** We will assume this embedded project is for ARM Cortex-M microcontrollers
131+
and will use the [template from rust-embedded project](https://github.com/rust-embedded/cortex-m-quickstart).
132+
133+
```sh
134+
criticalup run cargo generate --git https://github.com/rust-embedded/cortex-m-quickstart
135+
```
136+
137+
**Caveat:** This will generate a project directory inside `ferrocene-demo` since we are using a template.
118138

119-
#### Run your app using CriticalUp
139+
### Run your app using CriticalUp
120140

121141
The following command uses installed Ferrocene:
122142

123143
```shell
124144
criticalup run cargo run --release
125145
```
126146

127-
As you can see, you can simply pass `cargo` as a subcommand.
147+
As you can see, you can pass `cargo` as a subcommand.
148+
149+
> For GitHub Actions: See the step 'Run my app via Ferrocene and its toolchain' in [`build.yml`].
150+
151+
## GitHub settings for Actions
128152

129-
> See the step 'Run my app via Ferrocene and its toolchain' in [`build.yml`].
153+
### Push your project to GitHub
154+
155+
First, log into github.com and create a new project repo and copy the remote URL.
156+
The URL will be in the format of `git remote add origin https://github.com/OWNER/REPOSITORY.git`.
157+
158+
Git related commands are beyond the scope of this document but the steps are:
159+
160+
- Initialize your project as a Git repo: `git init`.
161+
- Add and commit all the files to Git: `git -am 'my awesome project'`.
162+
- Add the remote (from above): `git remote add origin https://github.com/OWNER/REPOSITORY.git`.
163+
- Push the code: `git push`.
164+
165+
### Add the CriticalUp Token to GitHub Action secrets
166+
167+
The CriticalUp Token you got from the [Ferrocene Customer Portal] must be set in your GitHub repo's Settings.
168+
169+
- Go to the 'Settings' tab of your GitHub repo.
170+
- Click 'Secrets and variables'.
171+
- Click 'Actions'.
172+
- Click 'New repository secret'.
173+
- Add Name as `CRITICALUP_TOKEN` and past the token from [Ferrocene Customer Portal] in the 'Secret' text area.
174+
175+
### Create a simple GitHub Action
176+
177+
An example of a fully working Github CI workflow file can be found in the workflow file [`build.yml`] of this demo project.
178+
179+
- When no workflow file in your project exists, copy the `build.yml` into the folder `.github/workflows`, otherwise
180+
copy the CI job `install-criticalup-build-run-my-app` into your existing workflow file.
181+
- Adapt the workflow if necessary, for example, to compile the project instead of run it.
182+
- We will use a single job so we don't need to cache anything. The job consists of multiple steps.
183+
- We will showcase only Ubuntu 20.04 in this exercise.
130184

131185
## References
132186

@@ -145,4 +199,4 @@ As you can see, you can simply pass `cargo` as a subcommand.
145199
[Ferrocene documentation]: https://public-docs.ferrocene.dev/main/index.html
146200
[rustup]: https://rustup.rs/
147201
[cargo]: https://doc.rust-lang.org/cargo/
148-
[`build.yml`]: ./.github/workflows/build.yml
202+
[`build.yml`]: ./.github/workflows/build.yml

0 commit comments

Comments
 (0)