Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 93d69c9

Browse files
authored
Improve packaging (#56)
* Include CPU runtime packages in projects * Refactor build.py * Remove CI task that copies libmediapipe It is no longer needed as the packaging now does it automatically.
1 parent f578a63 commit 93d69c9

File tree

6 files changed

+48
-27
lines changed

6 files changed

+48
-27
lines changed

.github/workflows/ci.yml

-4
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ jobs:
7171
- name: Build (.NET)
7272
run: dotnet build -c Debug src/${{env.PROJECT_NAME}}.sln
7373

74-
- name: Copy libmediapipe_c.* into Akihabara.tests
75-
run: cp $pwd/src/${{env.PROJECT_NAME}}/bin/Debug/${{env.NET_ENV}}/libmediapipe_c.* $pwd/src/${{env.PROJECT_NAME}}.Tests/bin/Debug/${{env.NET_ENV}}/
76-
shell: pwsh
77-
7874
# On Windows, ignore tests that can signal SIGABRT because it will abort the process.
7975
- name: Test (CPU, Windows)
8076
if: ${{ matrix.os.prettyname == 'Windows' }}

build.py

+27-20
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
_BAZEL_BIN_PATH = 'bazel-bin'
1515
_BUILD_PATH = 'build'
16-
_INSTALL_PATH = os.path.join('src', 'Akihabara')
16+
_INSTALL_PATH = 'src'
1717

1818
class Console:
1919
def __init__(self, verbose):
@@ -92,6 +92,7 @@ def __init__(self, command_args):
9292
Command.__init__(self, command_args)
9393

9494
self.system = platform.system()
95+
self.install = command_args.args.install
9596
self.desktop = command_args.args.desktop
9697
self.protobuf = command_args.args.protobuf
9798
# self.android = command_args.args.android
@@ -109,7 +110,7 @@ def run(self):
109110
self._run_command(self._build_proto_srcs_commands())
110111
self._unzip(
111112
os.path.join(_BAZEL_BIN_PATH, 'mediapipe_api', 'mediapipe_proto_srcs.zip'),
112-
os.path.join(_BUILD_PATH, 'Framework', 'Protobuf'))
113+
os.path.join(_BUILD_PATH, 'Akihabara', 'Framework', 'Protobuf'))
113114
self.console.info('Built protobuf sources')
114115

115116
# # Unity-specific requirements, not needed for .NET
@@ -129,11 +130,14 @@ def run(self):
129130
self.console.info('Built resource files')
130131

131132
if self.desktop:
132-
self.console.info('Building native libraries for Desktop...')
133+
self.console.info(f'Building native libraries for {self.system} Desktop...')
134+
135+
native_build_path = os.path.join(_BUILD_PATH, 'Runtime', f'Akihabara.Runtime.{self.system}_x64.CPU')
136+
133137
self._run_command(self._build_desktop_commands())
134138
self._unzip(
135139
os.path.join(_BAZEL_BIN_PATH, 'mediapipe_api', 'mediapipe_desktop.zip'),
136-
os.path.join(_BUILD_PATH, 'bin', 'Debug', 'net5.0'))
140+
native_build_path)
137141

138142
if self.include_opencv_libs:
139143
if self.opencv == 'cmake':
@@ -142,7 +146,7 @@ def run(self):
142146
self._run_command(self._build_opencv_libs())
143147
self._unzip(
144148
os.path.join(_BAZEL_BIN_PATH, 'mediapipe_api', 'opencv_libs.zip'),
145-
os.path.join(_BUILD_PATH, 'bin', 'Debug', 'net5.0', 'opencv'))
149+
os.path.join(native_build_path, 'opencv'))
146150

147151
self.console.info('Built native libraries for Desktop')
148152

@@ -165,21 +169,23 @@ def run(self):
165169

166170

167171
self.console.info('Printing build path...')
168-
for root, directories, files in os.walk(_BUILD_PATH, topdown=False):
172+
self._print_dir_tree(_BUILD_PATH)
173+
self.console.info('Done')
174+
175+
if self.install:
176+
self.console.info('Installing...')
177+
# _copytree fails on Windows, so run `cp -r` instead.
178+
self._copytree(_BUILD_PATH, _INSTALL_PATH)
179+
self._print_dir_tree(os.path.join(_INSTALL_PATH, 'bin'))
180+
self.console.info('Installed')
181+
182+
def _print_dir_tree(self, dir_path):
183+
for root, directories, files in os.walk(dir_path, topdown=False):
169184
for name in files:
170185
print(os.path.join(root, name))
171186
for name in directories:
172187
print(os.path.join(root, name) + '/')
173188

174-
self.console.info('Installing...')
175-
# _copytree fails on Windows, so run `cp -r` instead.
176-
self._copytree(_BUILD_PATH, _INSTALL_PATH)
177-
for root, directories, files in os.walk(os.path.join(_INSTALL_PATH, 'bin'), topdown=False):
178-
for name in files:
179-
print(os.path.join(root, name))
180-
for name in directories:
181-
print(os.path.join(root, name) + '/')
182-
self.console.info('Installed')
183189

184190
def _is_windows(self):
185191
return self.system == 'Windows'
@@ -389,11 +395,12 @@ def __init__(self):
389395
subparsers = self.argument_parser.add_subparsers(dest='command')
390396

391397
build_command_parser = subparsers.add_parser('build', help='Build and install native libraries')
392-
build_command_parser.add_argument('--protobuf', '-p', action=argparse.BooleanOptionalAction, help='Build C# protobuf sources for Akihabara')
393-
build_command_parser.add_argument('--desktop', '-d', choices=['cpu', 'gpu'])
394-
# build_command_parser.add_argument('--android', '-a', choices=['arm', 'arm64'])
395-
# build_command_parser.add_argument('--ios', '-i', choices=['arm64'])
396-
build_command_parser.add_argument('--resources', '-R', action=argparse.BooleanOptionalAction)
398+
build_command_parser.add_argument('--install', action=argparse.BooleanOptionalAction, help='Integrate built artifacts in the repository', default=True)
399+
build_command_parser.add_argument('--protobuf', action=argparse.BooleanOptionalAction, help='Build C# protobuf sources for Akihabara')
400+
build_command_parser.add_argument('--desktop', choices=['cpu', 'gpu'])
401+
# build_command_parser.add_argument('--android', choices=['arm', 'arm64'])
402+
# build_command_parser.add_argument('--ios', choices=['arm64'])
403+
build_command_parser.add_argument('--resources', action=argparse.BooleanOptionalAction)
397404
build_command_parser.add_argument('--compilation_mode', '-c', choices=['fastbuild', 'opt', 'dbg'], default='opt')
398405
build_command_parser.add_argument('--opencv', choices=['local', 'cmake'], default='local', help='Decide to which OpenCV to link for Desktop native libraries')
399406
build_command_parser.add_argument('--include_opencv_libs', action='store_true', help='Include OpenCV\'s native libraries for Desktop')

src/Akihabara.Tests/Akihabara.Tests.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@
1010
</ItemGroup>
1111
<ItemGroup>
1212
<ProjectReference Include="..\Akihabara\Akihabara.csproj" />
13+
<ProjectReference
14+
Include="..\Runtime\Akihabara.Runtime.Linux_x64.CPU\Akihabara.Runtime.Linux_x64.CPU.csproj"
15+
Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' " />
16+
<ProjectReference
17+
Include="..\Runtime\Akihabara.Runtime.Windows_x64.CPU\Akihabara.Runtime.Windows_x64.CPU.csproj"
18+
Condition=" '$(OS)' == 'Windows_NT' " />
1319
</ItemGroup>
1420
</Project>

src/Examples/Akihabara.Examples.FaceLandmarksOnRawIO/Akihabara.Examples.FaceLandmarksOnRawIO.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<ProjectReference
66
Include="..\..\Runtime\Akihabara.Runtime.Linux_x64.CPU\Akihabara.Runtime.Linux_x64.CPU.csproj"
77
Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' " />
8+
<ProjectReference
9+
Include="..\..\Runtime\Akihabara.Runtime.Windows_x64.CPU\Akihabara.Runtime.Windows_x64.CPU.csproj"
10+
Condition=" '$(OS)' == 'Windows_NT' " />
811
</ItemGroup>
912

1013
<PropertyGroup>

src/Examples/Akihabara.Examples.HelloWorld/Akihabara.Examples.HelloWorld.csproj

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
<ItemGroup>
44
<ProjectReference Include="..\..\Akihabara\Akihabara.csproj" />
5-
<!-- <ProjectReference -->
6-
<!-- Include="..\..\Runtime\Akihabara.Runtime.Linux_x64.CPU\Akihabara.Runtime.Linux_x64.CPU.csproj" -->
7-
<!-- Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' " /> -->
5+
<ProjectReference
6+
Include="..\..\Runtime\Akihabara.Runtime.Linux_x64.CPU\Akihabara.Runtime.Linux_x64.CPU.csproj"
7+
Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' " />
8+
<ProjectReference
9+
Include="..\..\Runtime\Akihabara.Runtime.Windows_x64.CPU\Akihabara.Runtime.Windows_x64.CPU.csproj"
10+
Condition=" '$(OS)' == 'Windows_NT' " />
811
</ItemGroup>
912

1013
<PropertyGroup>

src/Examples/Akihabara.Examples.OnRawIO/Akihabara.Examples.OnRawIO.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
<ItemGroup>
44
<ProjectReference Include="..\..\Akihabara\Akihabara.csproj" />
5+
<ProjectReference
6+
Include="..\..\Runtime\Akihabara.Runtime.Linux_x64.CPU\Akihabara.Runtime.Linux_x64.CPU.csproj"
7+
Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' " />
8+
<ProjectReference
9+
Include="..\..\Runtime\Akihabara.Runtime.Windows_x64.CPU\Akihabara.Runtime.Windows_x64.CPU.csproj"
10+
Condition=" '$(OS)' == 'Windows_NT' " />
511
</ItemGroup>
612

713
<PropertyGroup>

0 commit comments

Comments
 (0)