1
1
# Demo: Ferrocene and its toolchain within GitHub Action(s)
2
2
3
- This is a very simple demo.
3
+ This is a simplified demo.
4
4
5
5
## Prerequisites
6
6
@@ -10,11 +10,20 @@ This is a very simple demo.
10
10
11
11
## Steps to use Ferrocene in your project
12
12
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
14
14
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.
16
17
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.
18
27
19
28
Create a file in project root: ` criticalup.toml ` and paste the following content in it:
20
29
@@ -32,62 +41,43 @@ packages = [
32
41
33
42
Some highlights about CriticalUp and the project manifest:
34
43
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.
37
47
- ` criticalup install --project /path/to/my/manifest/criticalup.toml ` .
38
48
- Used to install Ferrocene and its releases for your project, and packages and dependencies for the release (like [ rustup] ).
39
49
- Also used to build/run your project (like [ cargo] ).
40
50
- You can use ` -${rustc-host} ` suffix to automatically have CriticalUp fill the current architecture triple.
41
51
42
- ### Get the CriticalUp Token to authenticate
52
+ ### Get the CriticalUp Token to authenticate: get your token
43
53
44
54
- To install any Ferrocene product/toolchain, you will need to get a token from the [ Ferrocene Customer Portal] .
45
55
This token can be created in your account.
46
56
- The tokens are at the [ Ferrocene CriticalUp Tokens] section of the portal.
47
57
- Once you are on the page, click "New Token", provide a memorable title for it, and once generated copy the token.
48
58
- The token is only shown once for security.
49
59
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
71
61
72
62
The [ Installing CriticalUp] ( https://criticalup.ferrocene.dev/install.html ) section of the [ Criticalup documentation] says to run:
73
63
74
64
``` shell
75
65
curl --proto ' =https' --tlsv1.2 -LsSf https://github.com/ferrocene/criticalup/releases/latest/download/criticalup-installer.sh | sh
76
66
```
77
67
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 ` ] .
79
69
80
- #### Test CriticalUp is installed
70
+ ### Test CriticalUp is installed
81
71
82
72
The following command does not require a token or authentication and can tell you available subcommands for CriticalUp.
83
73
84
74
``` shell
85
75
criticalup --help
86
76
```
87
77
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 ` ] .
89
79
90
- #### Authenticate CriticalUp
80
+ ### Authenticate CriticalUp
91
81
92
82
** This section assumes you have done the following from above:**
93
83
@@ -100,33 +90,97 @@ In your GitHub Action you can use the secret now as:
100
90
criticalup auth set ${{ secrets.CRITICALUP_TOKEN } }
101
91
```
102
92
103
- > See the step 'Authenticate CriticalUp' in [ ` build.yml ` ] .
93
+ > For GitHub Actions: See the step 'Authenticate CriticalUp' in [ ` build.yml ` ] .
104
94
105
- #### Install Ferrocene toolchain
95
+ ### Install Ferrocene toolchain
106
96
107
97
** This step assumes you have already done the following from above:**
108
98
109
99
- Add a project manifest to your repo
110
100
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 ` ).
112
102
113
103
``` shell
114
104
criticalup install
115
105
```
116
106
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.
118
138
119
- #### Run your app using CriticalUp
139
+ ### Run your app using CriticalUp
120
140
121
141
The following command uses installed Ferrocene:
122
142
123
143
``` shell
124
144
criticalup run cargo run --release
125
145
```
126
146
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
128
152
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.
130
184
131
185
## References
132
186
@@ -145,4 +199,4 @@ As you can see, you can simply pass `cargo` as a subcommand.
145
199
[ Ferrocene documentation ] : https://public-docs.ferrocene.dev/main/index.html
146
200
[ rustup ] : https://rustup.rs/
147
201
[ cargo ] : https://doc.rust-lang.org/cargo/
148
- [ `build.yml` ] : ./.github/workflows/build.yml
202
+ [ `build.yml` ] : ./.github/workflows/build.yml
0 commit comments