3. Use Cases¶
3.1. Installing Ferrocene¶
-
RUSTC_UC0_INST¶
Actor(s): User, tar (compression utility)
Input: A Ferrocene release tarball.
Output: The directory structure and contents of Ferrocene.
Environment constraints: tar is correctly installed.
Description:
The
userdownloads all the archives needed to install Ferrocene.The
userextracts each archive into the installation directory usingtar:tar -C path/to/installation -xf path/to/archive.tar.xz
3.2. Building a Library¶
3.2.1. rlib¶
-
RUSTC_UC1_RLIB¶
Actor(s): User, rustc.
Input: A Rust compilation unit.
Output: A static Rust library.
Environment constraints: Ferrocene is correctly installed and the environment is correctly set.
Description:
The
usercallsrustcwith the following command line arguments:--edition 2021 --crate-type rlib <path> # where <path> is the path to the root of the compilation unit, as a # positional argument.
rustcparses the command line arguments.rustcparses the Rust compilation unit.rustcanalyzes the Rust compilation unit.rustcgenerates LLVM IR for the Rust compilation unit.rustcinvokesLLVM, passing the generated LLVM IR along with LLVM-related arguments.LLVMgenerates a static Rust library.(Optional): If the
useris building a certified library, theusermust verify that only certified functions from the core library are used.
3.2.2. staticlib¶
-
RUSTC_UC2_STATICLIB¶
Actor: User, rustc.
Input: A Rust compilation unit.
Output: A C-compatible static library.
Environment constraints: Ferrocene is correctly installed and the environment is correctly set.
Description:
The
usercallsrustcwith the following command line arguments:--edition 2021 --crate-type staticlib <path> # where <path> is the path to the root of the compilation unit, as a # positional argument.
rustcparses the command line arguments.rustcparses the Rust compilation unit.rustcanalyzes the Rust compilation unit.rustcgenerates LLVM IR for the Rust compilation unit.rustcinvokesLLVM, passing the generated LLVM IR along with LLVM-related arguments.LLVMgenerates a C-compatible static library.(Optional): If the
useris building a certified library, theusermust verify that only certified functions from the core library are used.
3.3. Building an Executable¶
-
RUSTC_UC3_EXEC¶
Actor: User, rustc.
Input: A Rust compilation unit.
Output: A Rust executable.
Environment constraints: Ferrocene is correctly installed, the compilation unit has the proper file extension, and the environment is correctly set.
Description:
The
usercallsrustcwith the following command line arguments:--codegen-units 1 --edition 2021 <path> # where <path> is the path to the root of the compilation unit, as a # positional argument.
rustcparses the command line arguments.rustcparses the Rust compilation unit.rustcanalyzes the Rust compilation unit.rustcgenerates LLVM IR for the Rust compilation unit.rustcinvokesLLVM, passing the generated LLVM IR along with LLVM-related arguments.LLVMgenerates an object file.rustcinvokes the linker, passing the generated object file along with linker-related arguments.The linker generates a Rust executable.
(Optional): If the
useris building a certified executable, theusermust verify that only certified functions from the core library are used.
3.3.1. Linked to a static Rust library¶
-
RUSTC_UC4_EXEC_RLIB¶
Actor: User, rustc.
Input: A Rust compilation unit, a static Rust library.
Output: A Rust executable linked to a static Rust library.
Environment constraints: Ferrocene is correctly installed, a static
Rust library generated with the same rustc, the compilation unit has the proper
file extension, and the environment is correctly set. If multiple static Rust
libraries are used, then their names must be unique within the set of all
directories included by compiler argument -L.
Description:
(Optional): The
userperforms use caseRUSTC_UC1_RLIBto generate a static Rust library.The
usercallsrustcwith the following command line arguments:--codegen-units 1 --edition 2021 -L <directory> --extern <name> <path> # where <directory> is the path to the directory that contains the static # Rust library, <name> is the name of the static Rust library, and <path> # is the path to the root of the compilation unit, as a positional argument.
rustcparses the command line arguments.rustcparses the Rust compilation unit.rustcanalyzes both the Rust compilation unit and the Rust library.rustcgenerates LLVM IR for the Rust compilation unit.rustcinvokesLLVM, passing the generated LLVM IR along with LLVM-related arguments.LLVMgenerates an object file.rustcinvokes the linker, passing the generated object file along with linker-related arguments.The linker generates a Rust executable that links to a static Rust library.
(Optional): If the
useris building a certified executable, theusermust verify that only certified functions from the core library are used.
3.4. Building Mixed-Language Programs¶
-
RUSTC_UC5_EXEC_CLIB¶
Actor: User, rustc, a C toolchain.
Input: A Rust compilation unit, a C library.
Output: A Rust executable that links to a C library.
Environment constraints: The C and Ferrocene toolchains are installed,
the compilation unit has the proper file extension, and the environment is
correctly set. If multiple C libraries are used, then their names must be
unique within the set of all directories included by compiler argument -L.
Description:
(Optional): The
usergenerates a library using a C toolchain.The
usercallsrustcwith the following command line arguments:--codegen-units 1 --edition 2021 -L <directory> -l <name> <path> # where <directory> is the path to the directory that contains the C # library, <name> is the name of the C library, and <path> is the path to # the root of the compilation unit, as a positional argument.
rustcparses the command line arguments.rustcparses the Rust compilation unit.rustcanalyzes the Rust compilation unit.rustcgenerates LLVM IR for the Rust compilation unit.rustcinvokesLLVM, passing the generated LLVM IR along with LLVM-related arguments.LLVMgenerates an object file.rustcinvokes the linker, passing the generated object file along with linker-related arguments.The linker generates a Rust executable that links to a C library.
(Optional): If the
useris building a certified executable, theusermust verify that only certified functions from the core library are used.
3.5. Building a procedural macro and using it in another crate¶
Note
The second part “Use the proc-macro crate” can be done for any crate type.
It will be done on the example of an rlib, but this can be adapted by changing the passed --crate-type.
For the purpose of analysing potential errors related to procedural macros, the crate type of the second part does not matter.
-
RUSTC_UC6_PROC_MACRO¶
Actor(s): User, rustc.
Input: Two Rust compilation units.
Output: A static Rust library.
Environment constraints: Ferrocene is correctly installed and the environment is correctly set.
Description:
Compile the
proc-macrocrateThe
usercallsrustcwith the following command line arguments--edition 2021 --crate-name <name> --crate-type proc-macro --extern proc_macro <proc_macro_path> # <proc_macro_path> is the path to the root of the first compilation unit, as a positional argument. # <name> is the name given to the proc-macro library
rustcparses the command line arguments.rustcparses the Rust compilation unit.rustcanalyzes the Rust compilation unit.rustcgenerates LLVM IR for the Rust compilation unit.rustcinvokesLLVM, passing the generated LLVM IR along with LLVM-related arguments.LLVMgenerates an object file.rustcinvokes the linker, passing the generated object file along with linker-related arguments.The linker generates a dynamic Rust library
lib<name>.sothat links to theproc_macrolibrary.
Use the
proc-macrocrateThe
usercallsrustcwith the following command line arguments--edition 2021 --crate-type rlib --extern <name>=lib<name>.so <path> # <path> is the path to the root of the second compilation unit, as a positional argument. # <name> is the name given to the proc-macro library in the step before
rustcparses the command line arguments.rustcparses the Rust compilation unit.rustcdynamically loadslib<name>.sorustcexecutes all procedural macros on the syntax tree.rustcanalyzes the Rust compilation unit.rustcgenerates LLVM IR for the Rust compilation unit.rustcinvokes LLVM, passing the generated LLVM IR along with LLVM-related arguments.LLVMgenerates a static Rust library.(Optional): If the
useris building a certified executable, theusermust verify that only certified functions from thecorelibrary are used.