Skip to content

Commit

Permalink
build: update build.bat, env templates, remove duplicate 'rime.lib' i…
Browse files Browse the repository at this point in the history
…n WeaselDeploer

- update build.bat: build Win32 and x64 librime concurrently. optimize workflow and code style/comments
- update env templates: disable ARCH in env
- update WeaselDeployer project: remove duplicate rime.lib
  • Loading branch information
fxliang authored and lotem committed Mar 29, 2024
1 parent d918ace commit c1b4529
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 83 deletions.
4 changes: 2 additions & 2 deletions WeaselDeployer/WeaselDeployer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>rime.lib;rime.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>rime.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)\lib;$(BOOST_ROOT)\stage\lib;$(SolutionDir)\librime\build\lib\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<OutputFile>$(SolutionDir)output\Win32\$(ProjectName)$(TargetExt)</OutputFile>
</Link>
Expand All @@ -162,7 +162,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>rime.lib;rime.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>rime.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)\lib64;$(BOOST_ROOT)\stage\lib;$(SolutionDir)\librime\build\lib\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<OutputFile>$(SolutionDir)output\$(ProjectName)$(TargetExt)</OutputFile>
</Link>
Expand Down
229 changes: 150 additions & 79 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -93,42 +93,49 @@ if %build_rime% == 0 (
set build_weasel=1
)))))

rem quit WeaselServer.exe before building
cd /d %WEASEL_ROOT%
if exist output\weaselserver.exe (
output\weaselserver.exe /q
)

rem build booost
if %build_boost% == 1 (
call :build_boost
if errorlevel 1 exit /b 1
cd /d %WEASEL_ROOT%
)

rem -------------------------------------------------------------------------
rem build librime x64 and Win32
if %build_rime% == 1 (
if not exist librime\build.bat (
git submodule update --init --recursive
)

cd %WEASEL_ROOT%\librime
if not exist env.bat (
copy %WEASEL_ROOT%\env.bat env.bat
)
if not exist lib\opencc.lib (
call build.bat deps %rime_build_variant%
if errorlevel 1 goto error
rem clean cache before building
for %%a in ( build dist lib ^
deps\glog\build ^
deps\googletest\build ^
deps\leveldb\build ^
deps\marisa-trie\build ^
deps\opencc\build ^
deps\yaml-cpp\build ) do (
if exist %%a rd /s /q %%a
)
call build.bat %rime_build_variant%
if errorlevel 1 goto error

cd %WEASEL_ROOT%
copy /Y librime\dist\include\rime_*.h include\
if errorlevel 1 goto error
copy /Y librime\dist\lib\rime.lib lib\
if errorlevel 1 goto error
copy /Y librime\dist\lib\rime.dll output\
if errorlevel 1 goto error
rem build x64 librime
set ARCH=x64
call :build_librime_platform x64 %WEASEL_ROOT%\lib64 %WEASEL_ROOT%\output
rem build Win32 librime
set ARCH=Win32
call :build_librime_platform Win32 %WEASEL_ROOT%\lib %WEASEL_ROOT%\output\Win32
rem clean the modified file
rem git checkout .
rem git submodule foreach git checkout .
)

rem -------------------------------------------------------------------------
if %build_weasel% == 1 (
if not exist output\data\essay.txt (
set build_data=1
Expand Down Expand Up @@ -200,80 +207,144 @@ if %build_installer% == 1 (

goto end

rem -------------------------------------------------------------------------
rem build boost
:build_boost

set BJAM_OPTIONS_COMMON=-j%NUMBER_OF_PROCESSORS%^
--with-filesystem^
--with-json^
--with-locale^
--with-regex^
--with-serialization^
--with-system^
--with-thread^
define=BOOST_USE_WINAPI_VERSION=0x0603^
toolset=%BJAM_TOOLSET%^
link=static^
runtime-link=static^
--build-type=complete

set BJAM_OPTIONS_X86=%BJAM_OPTIONS_COMMON%^
architecture=x86^
address-model=32

set BJAM_OPTIONS_X64=%BJAM_OPTIONS_COMMON%^
architecture=x86^
address-model=64

set BJAM_OPTIONS_ARM32=%BJAM_OPTIONS_COMMON%^
define=BOOST_USE_WINAPI_VERSION=0x0A00^
architecture=arm^
address-model=32

set BJAM_OPTIONS_ARM64=%BJAM_OPTIONS_COMMON%^
define=BOOST_USE_WINAPI_VERSION=0x0A00^
architecture=arm^
address-model=64

cd /d %BOOST_ROOT%
if not exist b2.exe call bootstrap.bat
if errorlevel 1 goto error
b2 %BJAM_OPTIONS_X86% stage %BOOST_COMPILED_LIBS%
if errorlevel 1 goto error
b2 %BJAM_OPTIONS_X64% stage %BOOST_COMPILED_LIBS%
if errorlevel 1 goto error

if %build_arm64% == 1 (
b2 %BJAM_OPTIONS_ARM32% stage %BOOST_COMPILED_LIBS%
set BJAM_OPTIONS_COMMON=-j%NUMBER_OF_PROCESSORS%^
--with-filesystem^
--with-json^
--with-locale^
--with-regex^
--with-serialization^
--with-system^
--with-thread^
define=BOOST_USE_WINAPI_VERSION=0x0603^
toolset=%BJAM_TOOLSET%^
link=static^
runtime-link=static^
--build-type=complete

set BJAM_OPTIONS_X86=%BJAM_OPTIONS_COMMON%^
architecture=x86^
address-model=32

set BJAM_OPTIONS_X64=%BJAM_OPTIONS_COMMON%^
architecture=x86^
address-model=64

set BJAM_OPTIONS_ARM32=%BJAM_OPTIONS_COMMON%^
define=BOOST_USE_WINAPI_VERSION=0x0A00^
architecture=arm^
address-model=32

set BJAM_OPTIONS_ARM64=%BJAM_OPTIONS_COMMON%^
define=BOOST_USE_WINAPI_VERSION=0x0A00^
architecture=arm^
address-model=64

cd /d %BOOST_ROOT%
if not exist b2.exe call bootstrap.bat
if errorlevel 1 goto error
b2 %BJAM_OPTIONS_ARM64% stage %BOOST_COMPILED_LIBS%
b2 %BJAM_OPTIONS_X86% stage %BOOST_COMPILED_LIBS%
if errorlevel 1 goto error
)
exit /b
b2 %BJAM_OPTIONS_X64% stage %BOOST_COMPILED_LIBS%
if errorlevel 1 goto error

if %build_arm64% == 1 (
b2 %BJAM_OPTIONS_ARM32% stage %BOOST_COMPILED_LIBS%
if errorlevel 1 goto error
b2 %BJAM_OPTIONS_ARM64% stage %BOOST_COMPILED_LIBS%
if errorlevel 1 goto error
)
exit /b

rem ---------------------------------------------------------------------------
:build_data
copy %WEASEL_ROOT%\LICENSE.txt output\
copy %WEASEL_ROOT%\README.md output\README.txt
copy %WEASEL_ROOT%\plum\rime-install.bat output\
set plum_dir=plum
set rime_dir=output/data
set WSLENV=plum_dir:rime_dir
bash plum/rime-install %WEASEL_BUNDLED_RECIPES%
if errorlevel 1 goto error
exit /b
copy %WEASEL_ROOT%\LICENSE.txt output\
copy %WEASEL_ROOT%\README.md output\README.txt
copy %WEASEL_ROOT%\plum\rime-install.bat output\
set plum_dir=plum
set rime_dir=output/data
set WSLENV=plum_dir:rime_dir
bash plum/rime-install %WEASEL_BUNDLED_RECIPES%
if errorlevel 1 goto error
exit /b

rem ---------------------------------------------------------------------------
:build_opencc_data
if not exist %WEASEL_ROOT%\librime\share\opencc\TSCharacters.ocd2 (
if not exist %WEASEL_ROOT%\librime\share\opencc\TSCharacters.ocd2 (
cd %WEASEL_ROOT%\librime
call build.bat deps %rime_build_variant%
if errorlevel 1 goto error
)
cd %WEASEL_ROOT%
if not exist output\data\opencc mkdir output\data\opencc
copy %WEASEL_ROOT%\librime\share\opencc\*.* output\data\opencc\
if errorlevel 1 goto error
exit /b

rem ---------------------------------------------------------------------------
rem %1 : ARCH
rem %2 : push | pop , push to backup when pop to restore
:stash_build
pushd %WEASEL_ROOT%\librime
for %%a in ( build dist lib ^
deps\glog\build ^
deps\googletest\build ^
deps\leveldb\build ^
deps\marisa-trie\build ^
deps\opencc\build ^
deps\yaml-cpp\build ) do (
if "%2"=="push" (
if exist %%a move %%a %%a_%1
)
if "%2"=="pop" (
if exist %%a_%1 move %%a_%1 %%a
)
)
popd
exit /b

rem ---------------------------------------------------------------------------
rem %1 : ARCH
rem %2 : target_path of rime.lib, base %WEASEL_ROOT% or abs path
rem %3 : target_path of rime.dll, base %WEASEL_ROOT% or abs path
:build_librime_platform
rem restore backuped %1 build
call :stash_build %1 pop

cd %WEASEL_ROOT%\librime
if not exist env.bat (
copy %WEASEL_ROOT%\env.bat env.bat
)
if not exist lib\opencc.lib (
call build.bat deps %rime_build_variant%
if errorlevel 1 (
call :stash_build %1 push
goto error
)
)
call build.bat %rime_build_variant%
if errorlevel 1 (
call :stash_build %1 push
goto error
)

cd %WEASEL_ROOT%\librime
call build.bat deps %rime_build_variant%
call :stash_build %1 push

copy /Y %WEASEL_ROOT%\librime\dist_%1\include\rime_*.h %WEASEL_ROOT%\include\
if errorlevel 1 goto error
)
cd %WEASEL_ROOT%
if not exist output\data\opencc mkdir output\data\opencc
copy %WEASEL_ROOT%\librime\share\opencc\*.* output\data\opencc\
if errorlevel 1 goto error
exit /b
copy /Y %WEASEL_ROOT%\librime\dist_%1\lib\rime.lib %2\
if errorlevel 1 goto error
copy /Y %WEASEL_ROOT%\librime\dist_%1\lib\rime.dll %3\
if errorlevel 1 goto error

exit /b
rem ---------------------------------------------------------------------------

:error

echo error building weasel...

:end
Expand Down
2 changes: 1 addition & 1 deletion env.vs2019.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rem REQUIRED: path to Boost source directory
if not defined BOOST_ROOT set BOOST_ROOT=%WEASEL_ROOT%\deps\boost_1_78_0

rem OPTIONAL: architecture, Visual Studio version and platform toolset
set ARCH=Win32
rem set ARCH=Win32
set BJAM_TOOLSET=msvc-14.2
set CMAKE_GENERATOR="Visual Studio 16 2019"
set PLATFORM_TOOLSET=v142
Expand Down
2 changes: 1 addition & 1 deletion env.vs2022.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rem REQUIRED: path to Boost source directory
if not defined BOOST_ROOT set BOOST_ROOT=%WEASEL_ROOT%\deps\boost_1_78_0

rem OPTIONAL: architecture, Visual Studio version and platform toolset
set ARCH=Win32
rem set ARCH=Win32
set BJAM_TOOLSET=msvc-14.3
set CMAKE_GENERATOR="Visual Studio 17 2022"
set PLATFORM_TOOLSET=v143
Expand Down

0 comments on commit c1b4529

Please sign in to comment.