|
1 name: Setup Corrosion Tests |
|
2 description: "Internal helper action to setup the Environment for Corrosions tests" |
|
3 inputs: |
|
4 target_arch: |
|
5 required: true |
|
6 description: CMake target architecture |
|
7 abi: |
|
8 required: false |
|
9 description: msvc, gnu or darwin |
|
10 default: default |
|
11 cmake: |
|
12 required: true |
|
13 description: Cmake version |
|
14 rust: |
|
15 required: true |
|
16 description: Rust version |
|
17 generator: |
|
18 required: true |
|
19 description: CMake Generator (e.g Ninja) |
|
20 build_dir: |
|
21 required: true |
|
22 description: Path of the CMake build directory |
|
23 configure_params: |
|
24 required: false |
|
25 description: Additional parameters to pass to CMake configure step |
|
26 install_path: |
|
27 required: false |
|
28 description: CMake install prefix |
|
29 default: "" |
|
30 compiler: |
|
31 required: false |
|
32 description: Compiler to use. Valid options are clang, gcc, cl, default, or an empty string. |
|
33 default: "default" |
|
34 |
|
35 runs: |
|
36 using: composite |
|
37 steps: |
|
38 - name: Cache Cargo registry |
|
39 id: cache-registry |
|
40 uses: actions/cache@v4 |
|
41 with: |
|
42 path: ~/.cargo/registry |
|
43 key: ${{ runner.os }}-cargo-registry |
|
44 - name: Determine Rust OS |
|
45 id: determine_rust_os |
|
46 shell: bash |
|
47 run: | |
|
48 if [ "${{ runner.os }}" == "Windows" ]; then |
|
49 echo "os=pc-windows" >> $GITHUB_OUTPUT |
|
50 echo "host_abi=msvc" >> $GITHUB_OUTPUT |
|
51 elif [ "${{ runner.os }}" == "Linux" ]; then |
|
52 echo "os=unknown-linux" >> $GITHUB_OUTPUT |
|
53 echo "host_abi=gnu" >> $GITHUB_OUTPUT |
|
54 elif [ "${{ runner.os }}" == "macOS" ]; then |
|
55 echo "os=apple" >> $GITHUB_OUTPUT |
|
56 echo "host_abi=darwin" >> $GITHUB_OUTPUT |
|
57 fi |
|
58 - name: Determine Rust ABI |
|
59 id: determine_abi |
|
60 shell: bash |
|
61 run: | |
|
62 if [[ ! ( -z "${{ inputs.abi }}" || "${{ inputs.abi }}" == "default" ) ]]; then |
|
63 echo "abi=${{ inputs.abi }}" >> $GITHUB_OUTPUT |
|
64 elif [ "${{ runner.os }}" == "Linux" ]; then |
|
65 echo "abi=gnu" >> $GITHUB_OUTPUT |
|
66 elif [ "${{ runner.os }}" == "macOS" ]; then |
|
67 echo "abi=darwin" >> $GITHUB_OUTPUT |
|
68 else |
|
69 echo "abi=msvc" >> $GITHUB_OUTPUT |
|
70 fi |
|
71 - name: Determine if Cross-compiling |
|
72 id: determine_cross_compile |
|
73 shell: bash |
|
74 run: | |
|
75 # For now it is safe to assume that all github runners are x86_64 |
|
76 if [[ "${{ inputs.target_arch }}" != "x86_64" ]]; then |
|
77 echo "Cross-Compiling to ${{ inputs.target_arch }}" |
|
78 if [[ "${{ runner.os }}" == "macOS" ]]; then |
|
79 echo "system_name=-DCMAKE_SYSTEM_NAME=Darwin" >> $GITHUB_OUTPUT |
|
80 else |
|
81 # Either `Linux` or `Windows` |
|
82 echo "system_name=-DCMAKE_SYSTEM_NAME=${{ runner.os }}" >> $GITHUB_OUTPUT |
|
83 fi |
|
84 fi |
|
85 - name: Pick Compiler |
|
86 id: pick_compiler |
|
87 shell: bash |
|
88 run: > |
|
89 ./.github/scripts/determine_compiler.sh |
|
90 "${{ inputs.compiler }}" |
|
91 "${{ runner.os }}" |
|
92 "${{ steps.determine_abi.outputs.abi }}" |
|
93 "${{steps.determine_cross_compile.outputs.system_name}}" |
|
94 "${{inputs.target_arch}}" |
|
95 - name: Pick Generator |
|
96 id: pick_generator |
|
97 shell: bash |
|
98 run: | |
|
99 if [ "${{ inputs.generator }}" == "ninja" ]; then |
|
100 echo "generator=-GNinja" >> $GITHUB_OUTPUT |
|
101 elif [ "${{ inputs.generator }}" == "ninja-multiconfig" ];then |
|
102 echo "generator=-GNinja Multi-Config" >> $GITHUB_OUTPUT |
|
103 fi |
|
104 - name: Arch Flags |
|
105 id: arch_flags |
|
106 shell: bash |
|
107 run: | # Cross-compiling is currently only supported on Windows+MSVC with the default generator |
|
108 if [ "${{ runner.os }}" == "Windows" ]; then |
|
109 if [ "${{inputs.generator}}" == "default" ]; then |
|
110 if [ "${{ inputs.target_arch }}" == "x86_64" ]; then |
|
111 echo "msvc=amd64" >> $GITHUB_OUTPUT |
|
112 echo "cmake=-Ax64" >> $GITHUB_OUTPUT |
|
113 elif [ "${{ inputs.target_arch }}" == "i686" ]; then |
|
114 echo "msvc=amd64_x86" >> $GITHUB_OUTPUT |
|
115 echo "cmake=-AWin32" >> $GITHUB_OUTPUT |
|
116 elif [ "${{ inputs.target_arch }}" == "aarch64" ]; then |
|
117 echo "msvc=amd64_arm64" >> $GITHUB_OUTPUT |
|
118 echo "cmake=-AARM64" >> $GITHUB_OUTPUT |
|
119 fi |
|
120 elif [ "${{inputs.generator}}" == "ninja" ]; then |
|
121 # We don't do cross-compiling builds with Ninja |
|
122 # Todo: Why not (cross-compile)? |
|
123 echo "msvc=amd64" >> $GITHUB_OUTPUT |
|
124 fi |
|
125 elif [ "${{ runner.os }}" == "Linux" ]; then |
|
126 echo "cmake=-DRust_CARGO_TARGET=${{inputs.target_arch}}-${{steps.determine_rust_os.outputs.os}}-${{steps.determine_abi.outputs.abi}}" >> $GITHUB_OUTPUT |
|
127 fi |
|
128 - name: Determine Install Prefix |
|
129 id: install_prefix |
|
130 shell: bash |
|
131 run: | |
|
132 if [ ! -z "${{ inputs.install_path }}" ]; then |
|
133 echo "install_path=-DCMAKE_INSTALL_PREFIX=${{ inputs.install_path }}" >> $GITHUB_OUTPUT |
|
134 fi |
|
135 - name: Setup MSVC Development Environment |
|
136 uses: ilammy/msvc-dev-cmd@v1 |
|
137 with: |
|
138 arch: ${{ steps.arch_flags.outputs.msvc }} |
|
139 if: ${{ 'msvc' == steps.determine_abi.outputs.abi }} |
|
140 - name: Install CMake |
|
141 uses: lukka/get-cmake@519de0c7b4812477d74976b2523a9417f552d126 |
|
142 with: |
|
143 cmakeVersion: "${{ inputs.cmake }}" |
|
144 ninjaVersion: "~1.10.0" |
|
145 - name: Install Rust |
|
146 id: install_rust |
|
147 uses: dtolnay/rust-toolchain@master |
|
148 with: |
|
149 toolchain: ${{inputs.rust}} |
|
150 targets: ${{inputs.target_arch}}-${{steps.determine_rust_os.outputs.os}}-${{steps.determine_abi.outputs.abi}} |
|
151 - name: Install Cross Compiler |
|
152 shell: bash |
|
153 run: | |
|
154 if [[ "${{ inputs.target_arch }}" != 'x86_64' ]]; then |
|
155 echo "::group::apt-install" |
|
156 sudo apt-get update |
|
157 sudo apt-get install -y g++-$(echo "${{inputs.target_arch}}" | tr _ -)-linux-gnu |
|
158 echo "::endgroup::" |
|
159 fi |
|
160 if: ${{ 'Linux' == runner.os }} |
|
161 - name: Determine Configure Shell |
|
162 id: configure_shell |
|
163 shell: bash |
|
164 run: | |
|
165 if [ "${{ runner.os }}" == "Windows" ]; then |
|
166 echo "shell=pwsh" >> $GITHUB_OUTPUT |
|
167 else |
|
168 echo "shell=bash" >> $GITHUB_OUTPUT |
|
169 fi |
|
170 - name: Configure |
|
171 shell: ${{steps.configure_shell.outputs.shell}} |
|
172 run: > |
|
173 cmake |
|
174 "-S." |
|
175 "-B${{inputs.build_dir}}" |
|
176 "-DCORROSION_VERBOSE_OUTPUT=ON" |
|
177 "${{steps.arch_flags.outputs.cmake}}" |
|
178 "${{steps.pick_compiler.outputs.c_compiler}}" |
|
179 "${{steps.pick_compiler.outputs.cxx_compiler}}" |
|
180 "${{steps.determine_cross_compile.outputs.system_name}}" |
|
181 "${{steps.pick_generator.outputs.generator}}" |
|
182 ${{steps.install_prefix.outputs.install_path}} |
|
183 "-DRust_TOOLCHAIN=${{steps.install_rust.outputs.name}}" |
|
184 ${{ inputs.configure_params }} |