Skip to content

Commit

Permalink
Instructions to build Glow tools for win x86 using the MSYS environme…
Browse files Browse the repository at this point in the history
…nt (#3640)

Summary:
**Summary**
Add documentation with instructions to build Glow for Windows x86 using the MSYS MINGW environment.
This is oriented more towards delivering the Glow front-end tools (e.g. image-classifier) on the windows side for an out-of-the-box experience with Glow for Windows users (and not developers).
If users are happy with the user experience and functionality, they might become contributors (like myself).

**Documentation**
Added GlowWindowsBuildx86.md

**Fixes**
In order for the windows build to work some Cmake fixes were required.
Also the msys build signaled a warning in Type.h which is a potential bug (fixed that).

**Test Plan**
None. I guess you should try to follow the instructions and verify the build works.
You might also have a look on the compile warnings and see if there are some serious problems there (like I spotted the problem from Type.h).

**Proposal**
To reach more to end-users which are non-experts and want to give Glow a try using their Windows machine (very common case) using an out-of-the-box deliverable, I propose:

1. Automatize the windows build using the instructions I gave and insert the windows build as a stage in the CI pipeline. All that is required is a windows server on your side, setup the msys environment once, and run some automated script to build (the build itself takes only a couple of minutes)
2. Provide a link on the Glow front page to the latest Windows build (personally I would find that extremely useful - other might as well).

I attached a sketch of the bash script which does the build and package it. The package should also contain the "dot.exe" utility which I find extremely useful for converting the dot file generated with "-dump-graph-DAG" option to PDF for graph inspection with the command:
`dot -Tpdf graph.dot -o graph.pdf -Nfontname="Times New Roman,"`
[glow-build-win-x64.sh.txt](https://github.com/pytorch/glow/files/3743728/glow-build-win-x64.sh.txt)
The bash script can be called from the Windows cmd without entering the msys2 shell like this:
`C:/msys64/msys2_shell.cmd  -mingw64  -where C:/msys64/mingw64  -c "./glow-build-win-x64.sh"`
assuming the script is located in _C:/msys64/mingw64/glow-build-win-x64.sh_
Pull Request resolved: #3640

Differential Revision: D18375939

Pulled By: jfix71

fbshipit-source-id: 65339f78e61f7a0da8eb116550f74183bc388ed4
  • Loading branch information
CristinaEnescu authored and facebook-github-bot committed Nov 7, 2019
1 parent 20e7027 commit ca898cc
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 5 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Expand Up @@ -82,18 +82,18 @@ add_custom_target(CollectHeaders SOURCES ${header_files})
find_package(Git)
# Get the commit's short SHA1
execute_process(COMMAND
"${GIT_EXECUTABLE}" log -1 --pretty=format:"%h"
"${GIT_EXECUTABLE}" log -1 --pretty=format:%h
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_SHA1
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
add_definitions("-DGIT_SHA1=${GIT_SHA1}")
add_definitions("-DGIT_SHA1=\"${GIT_SHA1}\"")
# Get the date of the commit
execute_process(COMMAND
"${GIT_EXECUTABLE}" log -1 --pretty=format:"%ad" --date=short
"${GIT_EXECUTABLE}" log -1 --pretty=format:%ad --date=short
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_DATE
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
add_definitions("-DGIT_DATE=${GIT_DATE}")
add_definitions("-DGIT_DATE=\"${GIT_DATE}\"")

find_package(PNG)
if(PNG_FOUND)
Expand Down
98 changes: 98 additions & 0 deletions docs/GlowWindowsBuildx86.md
@@ -0,0 +1,98 @@
## Build Glow for Windows x86:
------------------------------

This document provides a short description about how to build Glow for Windows
using the MSYS2 MINGW build environment. The instructions below apply for the
**x86_64** build (64 bit). For the **x86** target build (32 bit) the instructions
are similar (replace *mingw64* with *mingw32* in all the instructions below).

### Setup the MSYS2 build environment:
1. Download and install Msys2 from the following location:

http://repo.msys2.org/distrib/x86_64/msys2-x86_64-20190524.exe

2. Start the Msys2 MinGW64 shell from the windows command prompt.
All the subsequent commands will be executed in the Msys2 shell.

```
C:\msys64\msys2_shell.cmd -mingw64
```

3. Install LLVM 8.0.1 manually (make sure NOT to install the latest available LLVM).
Do NOT use the command "**pacman -Su**" for updating all the installed packages since
Glow requires a specific LLVM version. Execute the commands below one at a time.

```
wget http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-llvm-8.0.1-1-any.pkg.tar.xz
wget http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-clang-8.0.1-1-any.pkg.tar.xz
wget http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-polly-8.0.1-1-any.pkg.tar.xz
pacman -U mingw-w64-x86_64-llvm-8.0.1-1-any.pkg.tar.xz
pacman -U mingw-w64-x86_64-clang-8.0.1-1-any.pkg.tar.xz
pacman -U mingw-w64-x86_64-polly-8.0.1-1-any.pkg.tar.xz
rm mingw-w64-x86_64-llvm-8.0.1-1-any.pkg.tar.xz
rm mingw-w64-x86_64-clang-8.0.1-1-any.pkg.tar.xz
rm mingw-w64-x86_64-polly-8.0.1-1-any.pkg.tar.xz
```

4. Install the dependencies required for Glow. During package installation it might be
required to restart the Msys2 shell. Execute the commands below one at a time.

```
pacman -Sy
pacman -S base-devel zip git mingw-w64-x86_64-toolchain
pacman -S make mingw-w64-x86_64-cmake mingw-w64-x86_64-protobuf
pacman -S mingw-w64-x86_64-libpng mingw-w64-x86_64-graphviz mingw-w64-x86_64-python3
pacman -S mingw-w64-x86_64-glog
```

### Build Glow:
1. Restart the Msys2 MinGW64 shell from the windows command prompt:

```
C:\msys64\msys2_shell.cmd -mingw64
```

2. Clone the Glow repository:

```
cd /mingw64
git clone https://github.com/pytorch/glow.git
```

3. Update the submodules:

```
cd glow
git submodule update --init --recursive
cd ..
```

4. Configure Cmake:

```
mkdir glow_build
cd glow_build
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release ../glow/
```

5. Build the project:

```
make -j 8
cd ..
```

6. Package Glow (apart from the executables some DLL dependencies are required from the Msys2 environment):

```
mkdir glow_package
cp glow_build/bin/model-compiler.exe glow_package
cp glow_build/bin/model-runner.exe glow_package
cp glow_build/bin/text-translator.exe glow_package
cp /mingw64/bin/libstdc++-6.dll glow_package
cp /mingw64/bin/zlib1.dll glow_package
cp /mingw64/bin/libwinpthread-1.dll glow_package
cp /mingw64/bin/libgcc_s_seh-1.dll glow_package
cp /mingw64/bin/libprotobuf.dll glow_package
cp /mingw64/bin/libpng16-16.dll glow_package
```
5 changes: 4 additions & 1 deletion lib/Backends/CPU/CMakeLists.txt
Expand Up @@ -13,7 +13,10 @@ if(NOT LLVM_LINK_BIN)
if(MSVC)
set(LLVM_LINK_BIN ${LLVM_BINARY_DIR}/$(Configuration)/bin/llvm-link)
else()
set(LLVM_LINK_BIN ${LLVM_BINARY_DIR}/bin/llvm-link)
find_program(LLVM_LINK_BIN NAMES llvm-link)
if(NOT EXISTS ${LLVM_LINK_BIN})
set(LLVM_LINK_BIN ${LLVM_BINARY_DIR}/bin/llvm-link)
endif()
endif()
endif()
if(NOT EXISTS ${LLVM_LINK_BIN} AND NOT MSVC)
Expand Down

0 comments on commit ca898cc

Please sign in to comment.