hunterzju/llvm-tutorial
cs.cmu.edu/academic/class/15745-s14/public/lectures
cd /d d:\llvm-home\
git clone git@gitcode.net:pubz/llvm-project.gitcd /d d:\llvm-home\llvm-project\
git status
#HEAD detached at llvmorg-11.0.0set PATH=%PATH%;D:\Python38\Scripts\;D:\Python38\;D:\cmake-3.25.0-windows-x86_64\bin;D:\MicrosoftVisualStudio2019Enterprise\VC\Tools\MSVC\14.28.29910\bin\Hostx64\x86;D:\MicrosoftVisualStudio2019Enterprise\MSBuild\Current\Bin
#cmake -S llvm -B build -G "Visual Studio 16 2019" -DLLVM_ENABLE_PROJECTS=mlir,polly -DLLVM_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS="clang;llvm" -DCMAKE_CXX_FLAGS="/bigobj" -DLLVM_TARGETS_TO_BUILD=X86 #废弃
cmake -S llvm -B build -G "Visual Studio 16 2019" -DLLVM_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CONFIGURATION_TYPES=Debug -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_CXX_LINK_FLAGS="/LIBPATH:.\\debug\\lib /LIB:.\\debug\\lib " -DLLVM_ENABLE_PROJECTS="clang;llvm;mlir;polly" -DCMAKE_CXX_FLAGS="/bigobj" -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_INCLUDE_TESTS=False -DLLVM_BUILD_TESTS=OFF
cd build
msbuild LLVM.sln
"""
mlir
llvm build
编译完后找mlir例子
cd build
find . -path *mlir*example*
编译成功的样子:
d:\llvm-home\llvm-project\mlir\examples\toy
解决办法: 改成全路径
..\..\..\..\Debug\lib\LLVMSupport.lib;..\..\..\..\Debug\lib\LLVMSupport.lib;..\..\..\..\Debug\lib\gtest_main.lib;..\..\..\..\Debug\lib\gtest.lib;
..\..\..\..\Debug\lib\LLVMSupport.lib;..\..\..\..\Debug\lib\LLVMSupport.lib;gtest_main.lib;gtest.lib;
#bashcd build
#find . -name "*.vcxproj" | xargs -I@ grep -Hn ";gtest_main.lib" @
#找到有这种相对路径的, 用py脚本处理这些文件
find . -name "*.vcxproj" | xargs -I@ cp -v @ @.original #备份
#/c/Windows/System32/chcp.com 936
find -path *unittests*.vcxproj -a -type f | xargs -I@ sh -c "cp -v @.original @; python /d/llvm-home/llvm-project/compile-fix/replace_vcxproj.py @" # 处理(可多次执行本行)
# -*- coding: UTF-8 -*-#pip install lxml
#d:/llvm-home/llvm-project/compile-fix/replace_vcxproj.pylibDir:str="D:\\llvm-home\\llvm-project\\build\\Debug\\lib"
def replace_vcxproj(fileFullPath: str):_text=Nonetext:str=Nonewith open(fileFullPath, encoding='utf-8') as f:text = f.read()if not ( text.__contains__(";gtest_main.lib") or text.__contains__(";gtest.lib") ):print("无需处理, 因为不含 ';gtest_main.lib' 和 ';gtest.lib'")return# 替换_text = text.replace(";gtest_main.lib", f";{libDir}\\gtest_main.lib") .replace(";gtest.lib", f";{libDir}\\gtest.lib")# 写入结果with open(fileFullPath, "w", encoding='utf-8') as of:of.write(_text)print(f'处理{fileFullPath}')if __name__=='__main__':import sysassert len(sys.argv) >= 1replace_vcxproj(sys.argv[1])
#https://gnuwin32.sourceforge.net/packages/diffutils.htm
cd /d/
wget https://nchc.dl.sourceforge.net/project/gnuwin32/diffutils/2.8.7-1/diffutils-2.8.7-1-bin.zip
wget https://nchc.dl.sourceforge.net/project/gnuwin32/diffutils/2.8.7-1/diffutils-2.8.7-1-dep.zipunzip diffutils-2.8.7-1-bin.zip -d /d/diffutils-2.8.7-1-bin/
unzip diffutils-2.8.7-1-dep.zip -d /d/diffutils-2.8.7-1-bin/tree -L 2 /d/diffutils-2.8.7-1-bin/
"""
/d/diffutils-2.8.7-1-bin/
├── bin
│ ├── cmp.exe
│ ├── diff.exe
│ ├── diff3.exe
│ ├── libiconv2.dll
│ ├── libintl3.dll
│ └── sdiff.exe
"""
删掉 polly-check-format.vcxproj 中 “…ScopDetection.h | diff …” 的diff部分,具体如下:
继续编译 可正常编译
set path=%path%;D:\diffutils-2.8.7-1-bin\bin\
cd d:\llvm-home\llvm-project\build\
msbuild LLVM.sln
JSONTest.cpp 中的不可见符号都去掉
file: D:\llvm-home\llvm-project\llvm\unittests\Support\JSONTest.cpp
// Direct tests of isUTF8 and fixUTF8. Internal uses are also tested elsewhere.
//...for (auto Invalid : std::vector>{{"lone trailing \x81\x82 bytes", "lone trailing a bytes"},{"missing trailing \xD0 bytes", "missing trailing a bytes"},{"truncated character \xD0", "truncated character a"},{"not \xC1\x80 the \xE0\x9f\xBF shortest \xF0\x83\x83\x83 encoding","not a the a shortest a encoding"},{"too \xF9\x80\x80\x80\x80 long", "too a long"},{"surrogate \xED\xA0\x80 invalid \xF4\x90\x80\x80","surrogate a invalid a"}}) {EXPECT_FALSE(isUTF8(Invalid.first)) << Invalid.first;EXPECT_EQ(fixUTF8(Invalid.first), Invalid.second);}
}
//...
差异见下图:
家里电脑和公司电脑 llvm-home所在盘符不一致解决: mklink 符号链接
#家里电脑目录为e:\llvm-home\ ;公司电脑目录为d:\llvm-home\, 文档中用的目录也是d:\llvm-home\
#所以在家里电脑 用 符号链接 d:\llvm-home 指向 e:\llvm-home#创建符号链接:
mklink /j d:\llvm-home e:\llvm-home
mklink /j d:\instrmcpp e:\instrmcpp#以下这种貌似也行:
mklink /D d:\instrmcpp e:\instrmcpp#查看符号链接:
dir /AL d:\
#2022/12/03 08:46 llvm-home [e:\llvm-home]
#2022/12/06 22:46 instrmjcpp [e:\instrmcpp]mklink /?
"""创建符号链接。
MKLINK [[/D] | [/H] | [/J]] Link Target/D 创建目录符号链接。默认为文件 符号链接。/H 创建硬链接而非符号链接。/J 创建目录联接。Link 指定新的符号链接名称。Target 指定新链接引用的路径 (相对或绝对)。"""
.lib 其实是 ar 类型的压缩包, 可以用 7z之类的解压软件打开
#基于: msys2
#7z解压.lib例子
export PATH=$PATH:/d/7-Zip/
7z x build/tools/mlir/lib/Dialect/Affine/Utils/obj.MLIRAffineUtils.dir/Debug/obj.MLIRAffineUtils.lib -o/e/tmp/ -y -x'!obj.*.dir'
#基于: msys2#把以下内容保存为文件 /d/search_func_in_lib_dir.sh
find . -name "*.lib" -a -type f | xargs -I@ sh -c "rm -fr /e/tmp/*; 7z x @ -o/e/tmp/ -y -x'r!obj.*.dir' >/dev/null ; echo @; grep -Hn getMutableSuccessorOperands @"#然后执行
sh /d/search_func_in_lib_dir.sh
#注意不要用 bash 否则会报错
下一篇:RabbitMQ之发布确认