forked from NREL/OpenStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
393 lines (326 loc) · 14.3 KB
/
buildCSharp.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
name: buildCSharpSDK
on:
push:
branches: [ master, CSharp ]
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
pull_request:
branches: [ master ]
env:
BUILD_TYPE: Release
jobs:
build-csharp:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
# fail-fast: Default is true, switch to false to allow one platform to fail and still run others
fail-fast: false
matrix:
name: [Ubuntu, macOS, macOS_arm64, Windows64, Windows32]
include:
- name: Ubuntu
os: ubuntu-22.04
- name: macOS
os: macos-13
- name: macOS_arm64
os: macos-14
- name: Windows64
os: windows-latest
- name: Windows32
os: windows-latest
steps:
- uses: actions/checkout@v4
# # If you need to rebuild for a specific branch or tag **after** you fixed the workflow and you have no other changes or only a few you can download from github
# with:
# ref: v3.8.0
#
# - name: download patched CMakeLists.txt
# shell: bash
# run: |
# rm CMakeLists.txt
# aria2c https://raw.githubusercontent.com/NREL/OpenStudio/CSharp/CMakeLists.txt
#
# # Alternatively, if you have made lots of changes, just use this
# - name: Soft reset to v3.8.0
# shell: bash
# run: |
# git fetch --all
# git reset --soft v3.8.0
- uses: actions/setup-python@v5
with:
python-version: 3.12 # only for conan, version doesn't matter much
- name: Install Conan
shell: bash
run: |
begin_group() { echo -e "::group::\033[93m$1\033[0m"; }
set -x
begin_group "Install conan 2"
python --version
pip install 'conan>2'
conan --version
echo -e "::endgroup::"
begin_group "Default profile"
if [ "$RUNNER_OS" == "Windows" ]; then
DIR_SEP="\\"
else
DIR_SEP="/"
fi
echo DIR_SEP=$DIR_SEP >> $GITHUB_ENV
export CONAN_USER_HOME="${{ github.workspace }}${DIR_SEP}conan-cache"
echo CONAN_USER_HOME="$CONAN_USER_HOME" >> $GITHUB_ENV
export CONAN_HOME="$CONAN_USER_HOME${DIR_SEP}.conan2"
echo CONAN_HOME="$CONAN_HOME" >> $GITHUB_ENV
export CONAN_PROFILE_DEFAULT="$CONAN_HOME${DIR_SEP}profiles${DIR_SEP}default"
echo CONAN_PROFILE_DEFAULT="$CONAN_PROFILE_DEFAULT" >> $GITHUB_ENV
conan profile detect --force --name default
cat $CONAN_PROFILE_DEFAULT
# Mac has the FreeBSD flavor of sed and MUST take a backup suffix...
sed -i.bak 's/cppstd=.*$/cppstd=20/g' $CONAN_PROFILE_DEFAULT
sed -i.bak 's/build_type=.*$/build_type=${{ env.BUILD_TYPE }}/g' $CONAN_PROFILE_DEFAULT
# Windows only
sed -i.bak 's/compiler.runtime_type=.*$/compiler.runtime_type=${{ env.BUILD_TYPE }}/g' $CONAN_PROFILE_DEFAULT
rm -Rf $CONAN_PROFILE_DEFAULT.bak || true
conan profile show
echo -e "::endgroup::"
begin_group "Global.conf"
echo "core:non_interactive = True" >> $CONAN_HOME/global.conf
echo "core.download:parallel = {{os.cpu_count() - 2}}" >> $CONAN_HOME/global.conf
echo "core.sources:download_cache = $CONAN_USER_HOME/.conan-download-cache" >> $CONAN_HOME/global.conf
cat $CONAN_HOME/global.conf
echo -e "::endgroup::"
begin_group "Remotes"
conan remote add --force nrel-v2 https://conan.openstudio.net/artifactory/api/conan/conan-v2
conan remote list
echo -e "::endgroup::"
- name: Configure CMake & build (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
begin_group() { echo -e "::group::\033[93m$1\033[0m"; }
set -x
begin_group "Install ninja"
if [ "$RUNNER_OS" == "macOS" ]; then
brew install ninja
export CC=clang
export CMAKE_OSX_ARCHITECTURES=x86_64
else
sudo apt update && sudo apt install -y -qq ninja-build
fi
echo -e "::endgroup::"
begin_group "Conan install"
if [ "$RUNNER_OS" == "macOS" ]; then
# Avoid "builtin __has_nothrow_assign is deprecated; use __is_nothrow_assignable instead" in boost/1.79 with recent clang
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=${{ env.BUILD_TYPE }} -o with_testing=False -o with_benchmark=False -o with_ruby=False -o with_python=False -o with_csharp=True -c tools.build:cxxflags="['-D_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']"
else
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=${{ env.BUILD_TYPE }} -o with_testing=False -o with_benchmark=False -o with_ruby=False -o with_python=False -o with_csharp=True
fi
echo -e "::endgroup::"
begin_group "CMake Configure"
cmake --preset conan-release \
-DBUILD_CSHARP_BINDINGS:BOOL=ON -DBUILD_NUGET_PACKAGE:BOOL=OFF \
-DBUILD_TESTING:BOOL=OFF -DBUILD_RUBY_BINDINGS:BOOL=OFF -DBUILD_PYTHON_BINDINGS:BOOL=OFF -DBUILD_CLI:BOOL=OFF
echo -e "::endgroup::"
begin_group "Build"
cmake --build --preset conan-release
echo -e "::endgroup::"
- name: Compile Windows 64
if: matrix.name == 'Windows64'
shell: cmd
run: |
echo "::group::Conan Install"
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator="Visual Studio 17 2022" -s compiler.cppstd=20 -s build_type=${{ env.BUILD_TYPE }} -o with_testing=False -o with_benchmark=False -o with_ruby=False -o with_python=False -o with_csharp=True
echo "::engroup::"
cmake --list-presets
echo "::group::CMake Configure"
call ./build/conanbuild.bat
cmake --preset conan-default ^
-DBUILD_CSHARP_BINDINGS:BOOL=ON -DBUILD_NUGET_PACKAGE:BOOL=OFF ^
-DBUILD_TESTING:BOOL=OFF -DBUILD_RUBY_BINDINGS:BOOL=OFF -DBUILD_PYTHON_BINDINGS:BOOL=OFF -DBUILD_CLI:BOOL=OFF
echo "::engroup::"
echo "::group::Build"
cmake --build --preset conan-release
echo "::engroup::"
- name: Install Dotnet x86
if: matrix.name == 'Windows32'
run: |
Invoke-WebRequest 'https://dotnetcli.azureedge.net/dotnet/Runtime/7.0.1/dotnet-runtime-7.0.1-win-x86.exe' -OutFile './dotnet-runtime-7.0.1-win-x86.exe'
./dotnet-runtime-7.0.1-win-x86.exe /install /quiet /norestart
dotnet --info
- name: Compile Windows 32
if: matrix.name == 'Windows32'
shell: cmd
run: |
echo "::group::Conan Install"
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator="Visual Studio 17 2022" -s compiler.cppstd=20 -s build_type=${{ env.BUILD_TYPE }} -o with_testing=False -o with_benchmark=False -o with_ruby=False -o with_python=False -o with_csharp=True -s:b arch=x86_64 -s:h arch=x86
echo "::engroup::"
echo "::group::CMake Configure"
call ./build/conanbuild.bat
cmake --preset conan-default ^
-DBUILD_CSHARP_BINDINGS:BOOL=ON -DBUILD_NUGET_PACKAGE:BOOL=OFF ^
-DBUILD_TESTING:BOOL=OFF -DBUILD_RUBY_BINDINGS:BOOL=OFF -DBUILD_PYTHON_BINDINGS:BOOL=OFF -DBUILD_CLI:BOOL=OFF
echo "::engroup::"
echo "::group::Build"
cmake --build --preset conan-release
echo "::engroup::"
- name: build nuget for Windows
if: runner.os == 'Windows'
run: |
dotnet pack ./build/csharp_wrapper/OpenStudio.csproj -o ./build/Products/csharp/Release/ -v normal
- name: build nuget for Linux
if: runner.os == 'Linux'
run: |
cp ./csharp/*.targets ./build/Products
ls ./build/Products
dotnet pack ./build/csharp_wrapper/OpenStudio.csproj -o ./build/Products/csharp/Release/ -v normal
- name: Fix dylib and build nuget for Mac
if: runner.os == 'macOS'
run: |
sudo install_name_tool -add_rpath "@loader_path/." ./build/Products/libopenstudio_csharp.dylib
sudo install_name_tool -delete_rpath "${{ github.workspace }}/build/Products" ./build/Products/libopenstudio_csharp.dylib
sudo install_name_tool -add_rpath "@loader_path/." ./build/Products/libopenstudio_model_csharp.dylib
sudo install_name_tool -delete_rpath "${{ github.workspace }}/build/Products" ./build/Products/libopenstudio_model_csharp.dylib
sudo install_name_tool -add_rpath "@loader_path/." ./build/Products/libopenstudio_translators_csharp.dylib
sudo install_name_tool -delete_rpath "${{ github.workspace }}/build/Products" ./build/Products/libopenstudio_translators_csharp.dylib
cp ./csharp/*.targets ./build/Products
ls ./build/Products
dotnet pack ./build/csharp_wrapper/OpenStudio.csproj -o ./build/Products/csharp/Release/ -v normal
- name: list files
run: |
echo "Listing the top directory=========================================="
ls
echo "Listing ./build/=========================================="
ls ./build/
echo "Listing ./build/Products/=========================================="
ls -R ./build/Products
- name: Zip Build/Source Artifact
run: |
7z a CSharp_${{ matrix.name }}.zip ./build/Products/csharp/Release/*.nupkg
7z a CSharp_${{ matrix.name }}_Src.zip ./build/csharp_wrapper/generated_sources ./build/csharp_wrapper/OpenStudio.csproj
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: CSharp_${{ matrix.name }}
path: CSharp_${{ matrix.name }}.zip
- name: Upload artifact generated_sources
uses: actions/upload-artifact@v4
with:
name: CSharp_${{ matrix.name }}_Src
path: CSharp_${{ matrix.name }}_Src.zip
- name: Upload artifact (if failed)
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}_Failed
path: |
./build/csharp_wrapper/
./build/Products/
Test_Windows:
name: "Test x86 and x64 nuget packages for windows"
runs-on: windows-latest
timeout-minutes: 20
needs: build-csharp
steps:
- uses: actions/checkout@v4
- name: Download CSharp_Windows32
uses: actions/download-artifact@v4
with:
name: CSharp_Windows32
- name: Download CSharp_Windows64
uses: actions/download-artifact@v4
with:
name: CSharp_Windows64
- name: unzip artifacts
run: |
Expand-Archive CSharp_Windows32.zip -DestinationPath x86
Expand-Archive CSharp_Windows64.zip -DestinationPath x64
Expand-Archive x86\*.nupkg -DestinationPath x86\package
Expand-Archive x64\*.nupkg -DestinationPath x64\package
ls -R
- name: merge x86 into x64
run: |
cp x64\package x64x86 -r
mv x64x86\lib x64x86\build
mkdir x64x86\build\netstandard2.0\x64
mkdir x64x86\build\net45\x64
mkdir x64x86\build\netstandard2.0\x86
mkdir x64x86\build\net45\x86
mv x64x86\build\netstandard2.0\*.dll x64x86\build\netstandard2.0\x64
mv x64x86\build\net45\*.dll x64x86\build\net45\x64
mv x86\package\lib\netstandard2.0\* x64x86\build\netstandard2.0\x86
mv x86\package\lib\net45\* x64x86\build\net45\x86
cp csharp\OpenStudio.targets x64x86\build\netstandard2.0\
cp csharp\OpenStudio.targets x64x86\build\net45\
cd x64x86
ls -R
- name: make a new nupkg for Windows
run: |
$VERSION = (Get-Item x64x86\build\netstandard2.0\x64\OpenStudio.dll).VersionInfo.FileVersion
echo $VERSION
Compress-Archive -U -Path x64x86\* -DestinationPath OpenStudio.$VERSION.nupkg
cp *.nupkg x64x86\OpenStudio.nupkg
ls
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: CSharp_Windows_x64x86
path: x64x86\OpenStudio.nupkg
- name: Install Dotnet x86
run: |
Invoke-WebRequest 'https://dotnetcli.azureedge.net/dotnet/Runtime/7.0.1/dotnet-runtime-7.0.1-win-x86.exe' -OutFile './dotnet-runtime-7.0.1-win-x86.exe'
./dotnet-runtime-7.0.1-win-x86.exe /install /quiet /norestart
dotnet --info
- name: Tests on Windows
run: |
$VERSION = (Get-Item x64x86\build\netstandard2.0\x64\OpenStudio.dll).VersionInfo.FileVersion
echo $VERSION
cp *.nupkg csharp/examples/OpenStudio.Tests/
cd csharp/examples/OpenStudio.Tests/
ls
dotnet remove OpenStudio.Tests.csproj package OpenStudio
dotnet remove OpenStudio.Tests.x86.csproj package OpenStudio
dotnet restore OpenStudio.Tests.csproj
dotnet restore OpenStudio.Tests.x86.csproj
dotnet add OpenStudio.Tests.csproj package OpenStudio -s "." -v $VERSION
dotnet add OpenStudio.Tests.x86.csproj package OpenStudio -s "." -v $VERSION
dotnet test OpenStudio.Tests.csproj --arch x64
dotnet clean OpenStudio.Tests.csproj
dotnet test OpenStudio.Tests.x86.csproj --arch x86
Test_Mac_ubuntu:
name: "Test 64-bit nuget packages for macos and ubuntu"
runs-on: ${{ matrix.os }}
strategy:
# fail-fast: Default is true, switch to false to allow one platform to fail and still run others
fail-fast: false
matrix:
name: [Ubuntu, macOS, macOS_arm64]
include:
- name: Ubuntu
os: ubuntu-latest
arch: x64
- name: macOS
os: macos-13
arch: x64
- name: macOS_arm64
os: macos-14
arch: arm64
timeout-minutes: 20
needs: build-csharp
steps:
- uses: actions/checkout@v4
- name: Download nuget
uses: actions/download-artifact@v4
with:
name: CSharp_${{ matrix.name }}
- name: unzip artifacts
run: |
7z e CSharp_${{ matrix.name }}.zip -o./nuget
ls nuget csharp/*
- name: Tests
run: |
cd csharp/examples/OpenStudio.Tests/
dotnet remove OpenStudio.Tests.csproj package OpenStudio
dotnet restore OpenStudio.Tests.csproj
dotnet add OpenStudio.Tests.csproj package OpenStudio -s "./../../../nuget"
dotnet clean OpenStudio.Tests.csproj
dotnet test OpenStudio.Tests.csproj --arch ${{ matrix.arch }} /p:Platform="${{ matrix.arch }}"