Skip to content

Commit

Permalink
子项目不再共享 Conan 依赖 (#601)
Browse files Browse the repository at this point in the history
* chore: 子项目之间不再共享 Conan 依赖
这可以有效减小可执行文件的体积

* chore: 修复编译

* chore: 不要复制 conanfile.txt

* Update build.yml
  • Loading branch information
Blinue authored May 12, 2023
1 parent f252e13 commit 92348d8
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/cache@v3
with:
path: ./.conan/data
key: ${{ runner.os }}-conan-${{ hashFiles('src/conanfile.txt') }}
key: ${{ runner.os }}-conan-${{ hashFiles('src/**/conanfile.txt') }}

- name: Restore NuGet packages
run: nuget restore
Expand Down
1 change: 0 additions & 1 deletion Magpie.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{00AB63C3-0CD3-4944-B8E6-58C86138618D}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
src\conanfile.py = src\conanfile.py
Directory.Build.props = Directory.Build.props
src\Solution.props = src\Solution.props
EndProjectSection
Expand Down
16 changes: 12 additions & 4 deletions src/CONAN_INSTALL/ConanInstall.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ conan config set storage.path=%CD%\..\..\.conan\data

IF %1 == Debug (
IF %2 == x64 (
conan install ..\conanfile.py --install-folder ..\..\.conan\x64\Debug --build=outdated -s build_type=Debug -s arch=x86_64 -s compiler.version=17 -s compiler.runtime=MTd --update
conan install ..\Magpie\conanfile.txt --install-folder ..\..\.conan\x64\Debug\Magpie --build=outdated -s build_type=Debug -s arch=x86_64 -s compiler.version=17 -s compiler.runtime=MTd --update
conan install ..\Magpie.Core\conanfile.txt --install-folder ..\..\.conan\x64\Debug\Magpie.Core --build=outdated -s build_type=Debug -s arch=x86_64 -s compiler.version=17 -s compiler.runtime=MTd --update
conan install ..\Magpie.App\conanfile.txt --install-folder ..\..\.conan\x64\Debug\Magpie.App --build=outdated -s build_type=Debug -s arch=x86_64 -s compiler.version=17 -s compiler.runtime=MTd --update
) ELSE (
conan install ..\conanfile.py --install-folder ..\..\.conan\ARM64\Debug --build=outdated -s build_type=Debug -s arch=armv8 -s compiler.version=17 -s compiler.runtime=MTd --update
conan install ..\Magpie\conanfile.txt --install-folder ..\..\.conan\ARM64\Debug\Magpie --build=outdated -s build_type=Debug -s arch=armv8 -s compiler.version=17 -s compiler.runtime=MTd --update
conan install ..\Magpie.Core\conanfile.txt --install-folder ..\..\.conan\ARM64\Debug\Magpie.Core --build=outdated -s build_type=Debug -s arch=armv8 -s compiler.version=17 -s compiler.runtime=MTd --update
conan install ..\Magpie.App\conanfile.txt --install-folder ..\..\.conan\ARM64\Debug\Magpie.App --build=outdated -s build_type=Debug -s arch=armv8 -s compiler.version=17 -s compiler.runtime=MTd --update
)
) ELSE (
IF %2 == x64 (
conan install ..\conanfile.py --install-folder ..\..\.conan\x64\Release --build=outdated -s build_type=Release -s arch=x86_64 -s compiler.version=17 -s compiler.runtime=MT --update
conan install ..\Magpie\conanfile.txt --install-folder ..\..\.conan\x64\Release\Magpie --build=outdated -s build_type=Release -s arch=x86_64 -s compiler.version=17 -s compiler.runtime=MT --update
conan install ..\Magpie.Core\conanfile.txt --install-folder ..\..\.conan\x64\Release\Magpie.Core --build=outdated -s build_type=Release -s arch=x86_64 -s compiler.version=17 -s compiler.runtime=MT --update
conan install ..\Magpie.App\conanfile.txt --install-folder ..\..\.conan\x64\Release\Magpie.App --build=outdated -s build_type=Release -s arch=x86_64 -s compiler.version=17 -s compiler.runtime=MT --update
) ELSE (
conan install ..\conanfile.py --install-folder ..\..\.conan\ARM64\Release --build=outdated -s build_type=Release -s arch=armv8 -s compiler.version=17 -s compiler.runtime=MT --update
conan install ..\Magpie\conanfile.txt --install-folder ..\..\.conan\ARM64\Release\Magpie --build=outdated -s build_type=Release -s arch=armv8 -s compiler.version=17 -s compiler.runtime=MT --update
conan install ..\Magpie.Core\conanfile.txt --install-folder ..\..\.conan\ARM64\Release\Magpie.Core --build=outdated -s build_type=Release -s arch=armv8 -s compiler.version=17 -s compiler.runtime=MT --update
conan install ..\Magpie.App\conanfile.txt --install-folder ..\..\.conan\ARM64\Release\Magpie.App --build=outdated -s build_type=Release -s arch=armv8 -s compiler.version=17 -s compiler.runtime=MT --update
)
)
5 changes: 5 additions & 0 deletions src/Magpie.App/Magpie.App.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,11 @@
<PRIResource Include="Resources.language-zh-Hans.resw" />
<PRIResource Include="Resources.language-zh-Hant.resw" />
</ItemGroup>
<ItemGroup>
<Text Include="conanfile.txt">
<DeploymentContent>false</DeploymentContent>
</Text>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\packages\Microsoft.UI.Xaml.2.8.2-prerelease.220830001\build\native\Microsoft.UI.Xaml.targets" Condition="Exists('..\..\packages\Microsoft.UI.Xaml.2.8.2-prerelease.220830001\build\native\Microsoft.UI.Xaml.targets')" />
Expand Down
3 changes: 3 additions & 0 deletions src/Magpie.App/Magpie.App.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,7 @@
<Filter>Strings</Filter>
</PRIResource>
</ItemGroup>
<ItemGroup>
<Text Include="conanfile.txt" />
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions src/Magpie.App/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[requires]
fmt/9.1.0
spdlog/1.11.0
parallel-hashmap/1.37
rapidjson/cci.20220822
kuba-zip/0.2.6

[generators]
visual_studio

[options]
fmt:header_only=True
spdlog:header_only=True
spdlog:no_exceptions=True
36 changes: 34 additions & 2 deletions src/Magpie.Core/EffectCacheManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Logger.h"
#include "CommonSharedConstants.h"
#include <d3dcompiler.h>
#include <zstd.h>
#include "Utils.h"

// YAS 暂不支持 ARM64
Expand Down Expand Up @@ -121,6 +122,37 @@ void serialize(Archive& ar, EffectDesc& o) {
ar& o.name& o.outSizeExpr& o.params& o.textures& o.samplers& o.passes& o.flags;
}

static bool ZstdCompress(std::span<const BYTE> src, std::vector<BYTE>& dest, int compressionLevel) noexcept {
dest.resize(ZSTD_compressBound(src.size()));
size_t size = ZSTD_compress(dest.data(), dest.size(), src.data(), src.size(), compressionLevel);

if (ZSTD_isError(size)) {
Logger::Get().Error(StrUtils::Concat("压缩失败:", ZSTD_getErrorName(size)));
return false;
}

dest.resize(size);
return true;
}

static bool ZstdDecompress(std::span<const BYTE> src, std::vector<BYTE>& dest) noexcept {
auto size = ZSTD_getFrameContentSize(src.data(), src.size());
if (size == ZSTD_CONTENTSIZE_UNKNOWN || size == ZSTD_CONTENTSIZE_ERROR) {
Logger::Get().Error("ZSTD_getFrameContentSize 失败");
return false;
}

dest.resize(size);
size = ZSTD_decompress(dest.data(), dest.size(), src.data(), src.size());
if (ZSTD_isError(size)) {
Logger::Get().Error(StrUtils::Concat("解压失败:", ZSTD_getErrorName(size)));
return false;
}

dest.resize(size);

return true;
}

static constexpr const uint32_t MAX_CACHE_COUNT = 127;

Expand Down Expand Up @@ -209,7 +241,7 @@ bool EffectCacheManager::Load(std::wstring_view effectName, std::wstring_view ha
return false;
}

if (!Utils::ZstdDecompress(compressedBuf, buf)) {
if (!ZstdDecompress(compressedBuf, buf)) {
Logger::Get().Error("解压缓存失败");
return false;
}
Expand Down Expand Up @@ -251,7 +283,7 @@ void EffectCacheManager::Save(std::wstring_view effectName, std::wstring_view ha
}


if (!Utils::ZstdCompress(buf, compressedBuf, CACHE_COMPRESSION_LEVEL)) {
if (!ZstdCompress(buf, compressedBuf, CACHE_COMPRESSION_LEVEL)) {
Logger::Get().Error("压缩缓存失败");
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Magpie.Core/Magpie.Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Text Include="conanfile.txt">
<DeploymentContent>false</DeploymentContent>
</Text>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
Expand Down
3 changes: 3 additions & 0 deletions src/Magpie.Core/Magpie.Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Text Include="conanfile.txt" />
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions src/Magpie.Core/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[requires]
fmt/9.1.0
spdlog/1.11.0
parallel-hashmap/1.37
muparser/2.3.4
yas/7.1.0
zstd/1.5.5
imgui/1.89.4

[generators]
visual_studio

[options]
fmt:header_only=True
spdlog:header_only=True
spdlog:no_exceptions=True

[imports]
./res/bindings, imgui_impl_dx11.* -> ../../../../src/Magpie.Core
5 changes: 5 additions & 0 deletions src/Magpie/Magpie.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@
<ItemGroup>
<Image Include="Magpie.ico" />
</ItemGroup>
<ItemGroup>
<Text Include="conanfile.txt">
<DeploymentContent>false</DeploymentContent>
</Text>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="XamlIslands.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
12 changes: 12 additions & 0 deletions src/Magpie/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[requires]
fmt/9.1.0
spdlog/1.11.0
parallel-hashmap/1.37

[generators]
visual_studio

[options]
fmt:header_only=True
spdlog:header_only=True
spdlog:no_exceptions=True
34 changes: 0 additions & 34 deletions src/Shared/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,6 @@
#include "Utils.h"
#include "Logger.h"
#include "StrUtils.h"
#include <zstd.h>


bool Utils::ZstdCompress(std::span<const BYTE> src, std::vector<BYTE>& dest, int compressionLevel) {
dest.resize(ZSTD_compressBound(src.size()));
size_t size = ZSTD_compress(dest.data(), dest.size(), src.data(), src.size(), compressionLevel);

if (ZSTD_isError(size)) {
Logger::Get().Error(StrUtils::Concat("压缩失败:", ZSTD_getErrorName(size)));
return false;
}

dest.resize(size);
return true;
}

bool Utils::ZstdDecompress(std::span<const BYTE> src, std::vector<BYTE>& dest) {
auto size = ZSTD_getFrameContentSize(src.data(), src.size());
if (size == ZSTD_CONTENTSIZE_UNKNOWN || size == ZSTD_CONTENTSIZE_ERROR) {
Logger::Get().Error("ZSTD_getFrameContentSize 失败");
return false;
}

dest.resize(size);
size = ZSTD_decompress(dest.data(), dest.size(), src.data(), src.size());
if (ZSTD_isError(size)) {
Logger::Get().Error(StrUtils::Concat("解压失败:", ZSTD_getErrorName(size)));
return false;
}

dest.resize(size);

return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
Expand Down
3 changes: 0 additions & 3 deletions src/Shared/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@ struct Utils {
T _exitScope;
};

static bool ZstdCompress(std::span<const BYTE> src, std::vector<BYTE>& dest, int compressionLevel);
static bool ZstdDecompress(std::span<const BYTE> src, std::vector<BYTE>& dest);

static uint64_t HashData(std::span<const BYTE> data) noexcept;
};
2 changes: 1 addition & 1 deletion src/Solution.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@

<!-- Conan 依赖 -->
<ImportGroup Label="PropertySheets">
<Import Project="..\.conan\$(Platform)\$(Configuration)\conanbuildinfo.props" Condition="exists('..\.conan\$(Platform)\$(Configuration)\conanbuildinfo.props')" />
<Import Project="..\.conan\$(Platform)\$(Configuration)\$(MSBuildProjectName)\conanbuildinfo.props" Condition="exists('..\.conan\$(Platform)\$(Configuration)\$(MSBuildProjectName)\conanbuildinfo.props')" />
</ImportGroup>
</Project>
29 changes: 0 additions & 29 deletions src/conanfile.py

This file was deleted.

0 comments on commit 92348d8

Please sign in to comment.