Repository: onnx/onnx
Pull request: update protobuf build options and build instructions
Signed-off-by: Ashwini Khade <askhade@microsoft.com>

**Description**
Updates cmakelist.txt to use ONNX_USE_PROTOBUF_SHARED_LIBS  to control Protobuf_USE_STATIC_LIBS options as well as these 2 are tightly coupled.

**Motivation and Context**
Fixes #3345 and #3017


Problem statement:
ONNX_USE_PROTOBUF_SHARED_LIBS should control Protobuf_USE_STATIC_LIBS
# Bug Report

### Describe the bug
ONNX_USE_PROTOBUF_SHARED_LIBS is set independently of Protobuf_USE_STATIC_LIBS even though the two are dependent on each other. Even the documentation says:

If ONNX_USE_PROTOBUF_SHARED_LIBS is ON then Protobuf_USE_STATIC_LIBS must be OFF and USE_MSVC_STATIC_RUNTIME must be 0. If ONNX_USE_PROTOBUF_SHARED_LIBS is OFF then Protobuf_USE_STATIC_LIBS must be ON.

Rather than relying on the user to set Protobuf_USE_STATIC_LIBS when calling cmake, it should be set before the call to find_package for protobuf based on the value of ONNX_USE_PROTOBUF_SHARED_LIBS. This way the user does not have to rely on their knowledge of what cmake does when find_package is called.

### System information
- OS Platform and Distribution (*e.g. Linux Ubuntu 16.04*): Windows 10
- ONNX version (*e.g. 1.7*):  1.7
- Python version: 3.8
- GCC/Compiler version (if compiling from source): VS2019
- CMake version:  3.19
- Protobuf version: 3.12.3
- Visual Studio version (if applicable): VS2019


### Reproduction instructions
1. Checkout protobuf 3.12.3
2. Correctly build static libraries with cmake and VS2019
-G "Visual Studio 16 2019" -A x64 -T host=x64
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=/path/to/protobuf/install
-Dprotobuf_BUILD_EXAMPLES=OFF
-Dprotobuf_BUILD_TESTS=OFF
-Dprotobuf_MSVC_STATIC_RUNTIME=OFF
-Dprotobuf_WITH_ZLIB=OFF
3. Checkout onnx-mlir
4. Build with cmake and VS2019
-G "Visual Studio 16 2019" -A x64 -T host=x64
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_PREFIX_PATH=/path/to/protobuf/install

### Expected behavior
Build succeeds

### Actual behavior
The build fails with multiple linker errors:
LNK2001: unresolved external symbol "__declspec(dllimport) ..."
LNK2019: unresolved external symbol "__declspec(dllimport) ..."
because neither onnx-mlir, nor onnx define Protobuf_USE_STATIC_LIBS and cmake silently defines PROTOBUF_USE_DLLS, but our protobuf is a static library.

Hints from issue discussion:
Hi @sstamenova,
Yes it is something needs to be fixed (already in the backlog) and there will be a PR to merge these two flags. Thank you for bringing this up.
I will send out a fix for this. Thanks!

Commit message: update readme

Signed-off-by: Ashwini Khade <askhade@microsoft.com>

Patch to review:
diff --git a/.azure-pipelines/Windows-CI.yml b/.azure-pipelines/Windows-CI.yml
index 0a4e3279edf..23724333bda 100644
--- a/.azure-pipelines/Windows-CI.yml
+++ b/.azure-pipelines/Windows-CI.yml
@@ -51,7 +51,7 @@ jobs:
       set ONNX_ML=$(onnx_ml)
       set ONNX_VERIFY_PROTO_3=$(onnx_verify_proto)
       set USE_MSVC_STATIC_RUNTIME=0
-      set CMAKE_ARGS=-DONNX_USE_PROTOBUF_SHARED_LIBS=ON -DProtobuf_USE_STATIC_LIBS=OFF -DONNX_USE_LITE_PROTO=ON -DONNX_WERROR=ON
+      set CMAKE_ARGS=-DONNX_USE_PROTOBUF_SHARED_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DONNX_WERROR=ON
 
       python setup.py --quiet install
       pytest
diff --git a/.github/workflows/release_win.yml b/.github/workflows/release_win.yml
index e8693a9c98a..9a8c2ca86c6 100644
--- a/.github/workflows/release_win.yml
+++ b/.github/workflows/release_win.yml
@@ -59,7 +59,7 @@ jobs:
     - name: Install python dependencies
       run: |
         python -m pip install --upgrade pip
-        python -m pip install numpy==1.16.6 wheel          
+        python -m pip install numpy==1.16.6 wheel
             
     - name: Build ONNX wheel
       run: |        
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 628dcaa8b86..4bbe05aaf45 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,11 +48,14 @@ if(NOT DEFINED ONNX_VERIFY_PROTO3)
   option(ONNX_VERIFY_PROTO3 "Generate code by proto3" ${PROTO3_ENABLED})
 endif()
 
- if (ONNX_USE_PROTOBUF_SHARED_LIBS)
+if(ONNX_USE_PROTOBUF_SHARED_LIBS)
   if(MSVC)
     #TODO: if ONNX_USE_MSVC_STATIC_RUNTIME is ON, it may not work
     add_definitions(-DPROTOBUF_USE_DLLS)
   endif()
+  set(Protobuf_USE_STATIC_LIBS OFF)
+else() 
+  set(Protobuf_USE_STATIC_LIBS ON)
 endif()
 
 # Set C++11 as standard for the whole project
diff --git a/README.md b/README.md
index 0f6859447d3..1e091d49061 100644
--- a/README.md
+++ b/README.md
@@ -50,116 +50,83 @@ Stay up to date with the latest ONNX news. [[Facebook](https://www.facebook.com/
 
 # Installation
 
-## Binaries
-
-A binary build of ONNX is available from [Conda](https://conda.io), in [conda-forge](https://conda-forge.org/):
-
+## Official Python packages
+ONNX released packages are published in PyPi.
 ```
-conda install -c conda-forge onnx
+pip install numpy protobuf==3.11.3
+pip install onnx
 ```
 
-## Source
-
-If you have installed onnx on your machine, please `pip uninstall onnx` first before the following process of build from source.
+[Weekly packages](https://test.pypi.org/project/onnx-weekly/) are published in test pypi to enable experimentation and early testing.
 
-### Linux and MacOS
-You will need an install of Protobuf and NumPy to build ONNX.  One easy
-way to get these dependencies is via
-[Anaconda](https://www.anaconda.com/download/):
 
+## Conda packages
+A binary build of ONNX is available from [Conda](https://conda.io), in [conda-forge](https://conda-forge.org/):
 ```
-# Use conda-forge protobuf, as default doesn't come with protoc
-conda install -c conda-forge protobuf numpy
+conda install -c conda-forge numpy protobuf==3.11.3 libprotobuf=3.11.3
+conda install -c conda-forge onnx
 ```
 
-You can then install ONNX from PyPi (Note: Set environment variable `ONNX_ML=1` for onnx-ml):
+You can also use the [onnx-dev docker image](https://hub.docker.com/r/onnx/onnx-dev) for a Linux-based installation without having to worry about dependency versioning.
 
-```
-pip install onnx
-```
 
-Alternatively, you can also build and install ONNX locally from source code:
+## Build ONNX from Source
+Before building from source uninstall any existing versions of onnx `pip uninstall onnx`.  
+If you are building ONNX from source, it is recommended that you also build Protobuf locally as a static library. Specifically on Windows, the version distributed with conda-forge is a DLL, but ONNX expects it to be a static library. Building protobuf locally also let's you control the verison of protobuf. The tested and recommended version is 3.11.3.
 
+Note for Windows : The instructions in this README assume you are using Visual Studio. It is recommended that you run all the commands from a shell started from "Developer Command Prompt for VS 2019" and keep the build system generator for cmake (e.g., cmake -G "Visual Studio 16 2019") consistent while building protobuf as well as ONNX.
 ```
 git clone https://github.com/onnx/onnx.git
 cd onnx
 git submodule update --init --recursive
-python setup.py install
-```
-
-Note: When installing in a non-Anaconda environment, make sure to install the Protobuf compiler before running the pip installation of onnx. For example, on Ubuntu:
-
-```
-sudo apt-get install protobuf-compiler libprotoc-dev
-pip install onnx
+# prefer lite proto
+set CMAKE_ARGS=-DONNX_USE_LITE_PROTO=ON
+pip install -e .
 ```
 
-### Windows
-If you are building ONNX from source on Windows, it is recommended that you also build Protobuf locally as a static library. The version distributed with conda-forge is a DLL, but ONNX expects it to be a static library.
-
-Note that the instructions in this README assume you are using Visual Studio. It is recommended that you run all the commands from a shell started from "Developer Command Prompt for VS 2019" and keep the build system generator for cmake (e.g., cmake -G "Visual Studio 16 2019") consistent.
-
-#### Build Protobuf and ONNX on Windows
-Step 1: Build Protobuf locally
+### Building Protobuf from source
+* **Windows**
 ```
 git clone https://github.com/protocolbuffers/protobuf.git
 cd protobuf
 git checkout v3.11.3
 cd cmake
-# Explicitly set -Dprotobuf_MSVC_STATIC_RUNTIME=OFF to make sure protobuf does not statically link to runtime library
-cmake -G -A -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=<protobuf_install_dir>
-# For example:
-# cmake -G "Visual Studio 16 2019" -A x64 -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=..\install
+cmake -G "Visual Studio 16 2019" -A $arch -DCMAKE_INSTALL_PREFIX=<protobug_install_dir> -DCMAKE_BUILD_TYPE=Release -Dprotobuf_MSVC_STATIC_RUNTIME=ON -DProtobuf_USE_STATIC_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF .
 msbuild protobuf.sln /m /p:Configuration=Release
 msbuild INSTALL.vcxproj /p:Configuration=Release
 ```
 
-Step 2: Build ONNX
+* **Linux**
 ```
-# Get ONNX
-git clone https://github.com/onnx/onnx.git
-cd onnx
+git clone https://github.com/protocolbuffers/protobuf.git
+cd protobuf
+git checkout v3.11.3
 git submodule update --init --recursive
-
-# Set environment variables to find protobuf and turn off static linking of ONNX to runtime library.
-# Even better option is to add it to user\system PATH so this step can be performed only once.
-# For more details check https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=vs-2017
-set PATH=<protobuf_install_dir>\bin;<protobuf_install_dir>\include;<protobuf_install_dir>\libs;%PATH%
-set USE_MSVC_STATIC_RUNTIME=0
-
-# use the static installed protobuf
-set CMAKE_ARGS=-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON
-
-# Optional: Set environment variable `ONNX_ML=1` for onnx-ml
-
-# Build ONNX
-python setup.py install
+mkdir build_source && cd build_source
+cmake ../cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
+make -j$(nproc)
+make install
 ```
 
-If you would prefer to use Protobuf from conda-forge instead of building Protobuf from source, you can use the following instructions.
-
-#### Build ONNX on Windows with Anaconda
-
+* **Mac**
+```
+export NUM_CORES=`sysctl -n hw.ncpu`
+brew update
+brew install autoconf && brew install automake
+wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.3/protobuf-cpp-3.11.3.tar.gz
+tar -xvf protobuf-cpp-3.11.3.tar.gz
+cd protobuf-3.11.3
+mkdir build_source && cd build_source
+cmake ../cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
+make -j${NUM_CORES}
+make install
 ```
-# Use conda-forge protobuf
-conda install -c conda-forge numpy libprotobuf=3.11.3 protobuf
-
-# Get ONNX
-git clone https://github.com/onnx/onnx.git
-cd onnx
-git submodule update --init --recursive
-
-# Set environment variable for ONNX to use protobuf shared lib
-set USE_MSVC_STATIC_RUNTIME=0
-set CMAKE_ARGS=-DONNX_USE_PROTOBUF_SHARED_LIBS=ON -DProtobuf_USE_STATIC_LIBS=OFF -DONNX_USE_LITE_PROTO=ON
 
-# Build ONNX
-# Optional: Set environment variable `ONNX_ML=1` for onnx-ml
+Once build is successful, update PATH to include protobuf paths. Example on Windows:  
+set PATH=<protobuf_install_dir>\bin;<protobuf_install_dir>\include;<protobuf_install_dir>\libs;%PATH%
 
-python setup.py install
-```
 
-#### Build ONNX on ARM 64
+### Build ONNX on ARM 64
 If you are building ONNX on an ARM 64 device, please make sure to install the dependencies appropriately.
 
 ```
@@ -178,21 +145,30 @@ python -c "import onnx"
 to verify it works.
 
 
-#### Common Errors
-**Environment variables**: `USE_MSVC_STATIC_RUNTIME` (should be 1 or 0, not ON or OFF)
+## Common Build Options
+For full list refer to CMakeLists.txt  
+**Environment variables**  
+* `USE_MSVC_STATIC_RUNTIME` should be 1 or 0, not ON or OFF. When set to 1 onnx links statically to runtime library.  
+**Default**: USE_MSVC_STATIC_RUNTIME=1
 
-**CMake variables**: `ONNX_USE_PROTOBUF_SHARED_LIBS`, `Protobuf_USE_STATIC_LIBS`
+* `DEBUG` should be 0 or 1. When set to 1 onnx is built in debug mode. or debug versions of the dependencies, you need to open the [CMakeLists file][CMakeLists] and append a letter `d` at the end of the package name lines. For example, `NAMES protobuf-lite` would become `NAMES protobuf-lited`.  
+**Default**: Debug=0
 
-If `ONNX_USE_PROTOBUF_SHARED_LIBS` is ON then `Protobuf_USE_STATIC_LIBS` must be OFF and `USE_MSVC_STATIC_RUNTIME` must be 0.
-If `ONNX_USE_PROTOBUF_SHARED_LIBS` is OFF then `Protobuf_USE_STATIC_LIBS` must be ON and `USE_MSVC_STATIC_RUNTIME` can be 1 or 0.
+**CMake variables**
+* `ONNX_USE_PROTOBUF_SHARED_LIBS` should be ON or OFF. If `ONNX_USE_PROTOBUF_SHARED_LIBS` is ON then `USE_MSVC_STATIC_RUNTIME` must be 0. If `ONNX_USE_PROTOBUF_SHARED_LIBS` is OFF then `USE_MSVC_STATIC_RUNTIME` can be 1 or 0.  
+**Default**: ONNX_USE_PROTOBUF_SHARED_LIBS=OFF USE_MSVC_STATIC_RUNTIME=1
 
-Note that the `import onnx` command does not work from the source checkout directory; in this case you'll see `ModuleNotFoundError: No module named 'onnx.onnx_cpp2py_export'`. Change into another directory to fix this error.
+* `ONNX_USE_LITE_PROTO` should be ON or OFF. When set to ON onnx uses lite protobuf instead of full protobuf.  
+**Default**: ONNX_USE_LITE_PROTO=OFF
 
-Building ONNX on Ubuntu works well, but on CentOS/RHEL and other ManyLinux systems, you might need to open the [CMakeLists file][CMakeLists] and replace all instances of `/lib` with `/lib64`.
+* `ONNX_WERROR` should be ON or OFF. When set to ON warnings are treated as errors.  
+**Default**: ONNX_WERROR=OFF in local builds, ON in CI and release pipelines.
 
-If you want to build ONNX on Debug mode, remember to set the environment variable `DEBUG=1`. For debug versions of the dependencies, you need to open the [CMakeLists file][CMakeLists] and append a letter `d` at the end of the package name lines. For example, `NAMES protobuf-lite` would become `NAMES protobuf-lited`.
 
-You can also use the [onnx-dev docker image](https://hub.docker.com/r/onnx/onnx-dev) for a Linux-based installation without having to worry about dependency versioning.
+## Common Errors
+* Note that the `import onnx` command does not work from the source checkout directory; in this case you'll see `ModuleNotFoundError: No module named 'onnx.onnx_cpp2py_export'`. Change into another directory to fix this error.
+
+* Building ONNX on Ubuntu works well, but on CentOS/RHEL and other ManyLinux systems, you might need to open the [CMakeLists file][CMakeLists] and replace all instances of `/lib` with `/lib64`.
 
 # Testing
 
diff --git a/cmake/summary.cmake b/cmake/summary.cmake
index 695fc8b08a2..74c7230c5ac 100644
--- a/cmake/summary.cmake
+++ b/cmake/summary.cmake
@@ -21,6 +21,7 @@ function (onnx_print_configuration_summary)
   message(STATUS "  ONNX NAMESPACE            : ${ONNX_NAMESPACE}")
   message(STATUS "  ONNX_USE_LITE_PROTO       : ${ONNX_USE_LITE_PROTO}")
   message(STATUS "  USE_PROTOBUF_SHARED_LIBS  : ${ONNX_USE_PROTOBUF_SHARED_LIBS}")
+  message(STATUS "  Protobuf_USE_STATIC_LIBS  : ${Protobuf_USE_STATIC_LIBS}")
   message(STATUS "  ONNX_DISABLE_EXCEPTIONS   : ${ONNX_DISABLE_EXCEPTIONS}")
   message(STATUS "  ONNX_WERROR               : ${ONNX_WERROR}")
   message(STATUS "  ONNX_BUILD_TESTS          : ${ONNX_BUILD_TESTS}")


Code review comments:
diff_hunk: @@ -50,116 +50,83 @@ Stay up to date with the latest ONNX news. [[Facebook](https://www.facebook.com/
 
 # Installation
 
-## Binaries
-
-A binary build of ONNX is available from [Conda](https://conda.io), in [conda-forge](https://conda-forge.org/):
-
+## Official Python packages
+ONNX released packages are published in PyPi.
 ```
-conda install -c conda-forge onnx
+pip install numpy protobuf==3.11.3
+pip install onnx
 ```
 
-## Source
-
-If you have installed onnx on your machine, please `pip uninstall onnx` first before the following process of build from source.
+[Weekly packages](https://test.pypi.org/project/onnx-weekly/) are published in test pypi to enable experimentation and early testing.
 
-### Linux and MacOS
-You will need an install of Protobuf and NumPy to build ONNX.  One easy
-way to get these dependencies is via
-[Anaconda](https://www.anaconda.com/download/):
 
+## Conda packages
+A binary build of ONNX is available from [Conda](https://conda.io), in [conda-forge](https://conda-forge.org/):
 ```
-# Use conda-forge protobuf, as default doesn't come with protoc
-conda install -c conda-forge protobuf numpy
+conda install -c conda-forge numpy protobuf==3.11.3 libprotobuf=3.11.3
+conda install -c conda-forge onnx
 ```
 
-You can then install ONNX from PyPi (Note: Set environment variable `ONNX_ML=1` for onnx-ml):
+You can also use the [onnx-dev docker image](https://hub.docker.com/r/onnx/onnx-dev) for a Linux-based installation without having to worry about dependency versioning.
 
-```
-pip install onnx
-```
 
-Alternatively, you can also build and install ONNX locally from source code:
+## Build ONNX from Source
+Before building from source uninstall any existing versions of onnx `pip uninstall onnx`.  
+If you are building ONNX from source, it is recommended that you also build Protobuf locally as a static library. Specifically on Windows, the version distributed with conda-forge is a DLL, but ONNX expects it to be a static library. Building protobuf locally also let's you control the verison of protobuf. The tested and recommended version is 3.11.3.
 
+Note for Windows : The instructions in this README assume you are using Visual Studio. It is recommended that you run all the commands from a shell started from "Developer Command Prompt for VS 2019" and keep the build system generator for cmake (e.g., cmake -G "Visual Studio 16 2019") consistent while building protobuf as well as ONNX.
 ```
 git clone https://github.com/onnx/onnx.git
 cd onnx
 git submodule update --init --recursive
-python setup.py install
-```
-
-Note: When installing in a non-Anaconda environment, make sure to install the Protobuf compiler before running the pip installation of onnx. For example, on Ubuntu:
-
-```
-sudo apt-get install protobuf-compiler libprotoc-dev
-pip install onnx
+# prefer lite proto
+set CMAKE_ARGS=-DONNX_USE_LITE_PROTO=ON
+pip install -e .
 ```
 
-### Windows
-If you are building ONNX from source on Windows, it is recommended that you also build Protobuf locally as a static library. The version distributed with conda-forge is a DLL, but ONNX expects it to be a static library.
-
-Note that the instructions in this README assume you are using Visual Studio. It is recommended that you run all the commands from a shell started from "Developer Command Prompt for VS 2019" and keep the build system generator for cmake (e.g., cmake -G "Visual Studio 16 2019") consistent.
-
-#### Build Protobuf and ONNX on Windows
-Step 1: Build Protobuf locally
+### Building Protobuf from source
+* **Windows**
 ```
 git clone https://github.com/protocolbuffers/protobuf.git
 cd protobuf
 git checkout v3.11.3
 cd cmake
-# Explicitly set -Dprotobuf_MSVC_STATIC_RUNTIME=OFF to make sure protobuf does not statically link to runtime library
-cmake -G -A -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=<protobuf_install_dir>
-# For example:
-# cmake -G "Visual Studio 16 2019" -A x64 -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=..\install
+cmake -G "Visual Studio 16 2019" -A $arch -DCMAKE_INSTALL_PREFIX=<protobug_install_dir> -DCMAKE_BUILD_TYPE=Release -Dprotobuf_MSVC_STATIC_RUNTIME=ON -DProtobuf_USE_STATIC_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF .
 msbuild protobuf.sln /m /p:Configuration=Release
 msbuild INSTALL.vcxproj /p:Configuration=Release
 ```
 
-Step 2: Build ONNX
+* **Linux**
 ```
-# Get ONNX
-git clone https://github.com/onnx/onnx.git
-cd onnx
+git clone https://github.com/protocolbuffers/protobuf.git
+cd protobuf
+git checkout v3.11.3
 git submodule update --init --recursive
-
-# Set environment variables to find protobuf and turn off static linking of ONNX to runtime library.
-# Even better option is to add it to user\system PATH so this step can be performed only once.
-# For more details check https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=vs-2017
-set PATH=<protobuf_install_dir>\bin;<protobuf_install_dir>\include;<protobuf_install_dir>\libs;%PATH%
-set USE_MSVC_STATIC_RUNTIME=0
-
-# use the static installed protobuf
-set CMAKE_ARGS=-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON
-
-# Optional: Set environment variable `ONNX_ML=1` for onnx-ml
-
-# Build ONNX
-python setup.py install
+mkdir build_source && cd build_source
+cmake ../cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
path: README.md
text: @user1:
protobuf_BUILD_SHARED_LIBS is a better option than BUILD_SHARED_LIBS since BUILD_SHARED_LIBS can be overwritten by passing a different value for protobuf_BUILD_SHARED_LIBS. It also makes it consistent with Windows.

diff_hunk: @@ -50,116 +50,83 @@ Stay up to date with the latest ONNX news. [[Facebook](https://www.facebook.com/
 
 # Installation
 
-## Binaries
-
-A binary build of ONNX is available from [Conda](https://conda.io), in [conda-forge](https://conda-forge.org/):
-
+## Official Python packages
+ONNX released packages are published in PyPi.
 ```
-conda install -c conda-forge onnx
+pip install numpy protobuf==3.11.3
+pip install onnx
 ```
 
-## Source
-
-If you have installed onnx on your machine, please `pip uninstall onnx` first before the following process of build from source.
+[Weekly packages](https://test.pypi.org/project/onnx-weekly/) are published in test pypi to enable experimentation and early testing.
 
-### Linux and MacOS
-You will need an install of Protobuf and NumPy to build ONNX.  One easy
-way to get these dependencies is via
-[Anaconda](https://www.anaconda.com/download/):
 
+## Conda packages
+A binary build of ONNX is available from [Conda](https://conda.io), in [conda-forge](https://conda-forge.org/):
 ```
-# Use conda-forge protobuf, as default doesn't come with protoc
-conda install -c conda-forge protobuf numpy
+conda install -c conda-forge numpy protobuf==3.11.3 libprotobuf=3.11.3
+conda install -c conda-forge onnx
 ```
 
-You can then install ONNX from PyPi (Note: Set environment variable `ONNX_ML=1` for onnx-ml):
+You can also use the [onnx-dev docker image](https://hub.docker.com/r/onnx/onnx-dev) for a Linux-based installation without having to worry about dependency versioning.
 
-```
-pip install onnx
-```
 
-Alternatively, you can also build and install ONNX locally from source code:
+## Build ONNX from Source
+Before building from source uninstall any existing versions of onnx `pip uninstall onnx`.  
+If you are building ONNX from source, it is recommended that you also build Protobuf locally as a static library. Specifically on Windows, the version distributed with conda-forge is a DLL, but ONNX expects it to be a static library. Building protobuf locally also let's you control the verison of protobuf. The tested and recommended version is 3.11.3.
 
+Note for Windows : The instructions in this README assume you are using Visual Studio. It is recommended that you run all the commands from a shell started from "Developer Command Prompt for VS 2019" and keep the build system generator for cmake (e.g., cmake -G "Visual Studio 16 2019") consistent while building protobuf as well as ONNX.
 ```
 git clone https://github.com/onnx/onnx.git
 cd onnx
 git submodule update --init --recursive
-python setup.py install
-```
-
-Note: When installing in a non-Anaconda environment, make sure to install the Protobuf compiler before running the pip installation of onnx. For example, on Ubuntu:
-
-```
-sudo apt-get install protobuf-compiler libprotoc-dev
-pip install onnx
+# prefer lite proto
+set CMAKE_ARGS=-DONNX_USE_LITE_PROTO=ON
+pip install -e .
 ```
 
-### Windows
-If you are building ONNX from source on Windows, it is recommended that you also build Protobuf locally as a static library. The version distributed with conda-forge is a DLL, but ONNX expects it to be a static library.
-
-Note that the instructions in this README assume you are using Visual Studio. It is recommended that you run all the commands from a shell started from "Developer Command Prompt for VS 2019" and keep the build system generator for cmake (e.g., cmake -G "Visual Studio 16 2019") consistent.
-
-#### Build Protobuf and ONNX on Windows
-Step 1: Build Protobuf locally
+### Building Protobuf from source
+* **Windows**
 ```
 git clone https://github.com/protocolbuffers/protobuf.git
 cd protobuf
 git checkout v3.11.3
 cd cmake
-# Explicitly set -Dprotobuf_MSVC_STATIC_RUNTIME=OFF to make sure protobuf does not statically link to runtime library
-cmake -G -A -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=<protobuf_install_dir>
-# For example:
-# cmake -G "Visual Studio 16 2019" -A x64 -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=..\install
+cmake -G "Visual Studio 16 2019" -A $arch -DCMAKE_INSTALL_PREFIX=<protobug_install_dir> -DCMAKE_BUILD_TYPE=Release -Dprotobuf_MSVC_STATIC_RUNTIME=ON -DProtobuf_USE_STATIC_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF .
path: README.md
text: @user1:
Incidentally, if you are building with Visual Studio, the CMAKE_BUILD_TYPE variable should not be needed.

diff_hunk: @@ -50,116 +50,83 @@ Stay up to date with the latest ONNX news. [[Facebook](https://www.facebook.com/
 
 # Installation
 
-## Binaries
-
-A binary build of ONNX is available from [Conda](https://conda.io), in [conda-forge](https://conda-forge.org/):
-
+## Official Python packages
+ONNX released packages are published in PyPi.
 ```
-conda install -c conda-forge onnx
+pip install numpy protobuf==3.11.3
+pip install onnx
 ```
 
-## Source
-
-If you have installed onnx on your machine, please `pip uninstall onnx` first before the following process of build from source.
+[Weekly packages](https://test.pypi.org/project/onnx-weekly/) are published in test pypi to enable experimentation and early testing.
 
-### Linux and MacOS
-You will need an install of Protobuf and NumPy to build ONNX.  One easy
-way to get these dependencies is via
-[Anaconda](https://www.anaconda.com/download/):
 
+## Conda packages
+A binary build of ONNX is available from [Conda](https://conda.io), in [conda-forge](https://conda-forge.org/):
 ```
-# Use conda-forge protobuf, as default doesn't come with protoc
-conda install -c conda-forge protobuf numpy
+conda install -c conda-forge numpy protobuf==3.11.3 libprotobuf=3.11.3
+conda install -c conda-forge onnx
 ```
 
-You can then install ONNX from PyPi (Note: Set environment variable `ONNX_ML=1` for onnx-ml):
+You can also use the [onnx-dev docker image](https://hub.docker.com/r/onnx/onnx-dev) for a Linux-based installation without having to worry about dependency versioning.
 
-```
-pip install onnx
-```
 
-Alternatively, you can also build and install ONNX locally from source code:
+## Build ONNX from Source
+Before building from source uninstall any existing versions of onnx `pip uninstall onnx`.  
+If you are building ONNX from source, it is recommended that you also build Protobuf locally as a static library. Specifically on Windows, the version distributed with conda-forge is a DLL, but ONNX expects it to be a static library. Building protobuf locally also let's you control the verison of protobuf. The tested and recommended version is 3.11.3.
 
+Note for Windows : The instructions in this README assume you are using Visual Studio. It is recommended that you run all the commands from a shell started from "Developer Command Prompt for VS 2019" and keep the build system generator for cmake (e.g., cmake -G "Visual Studio 16 2019") consistent while building protobuf as well as ONNX.
 ```
 git clone https://github.com/onnx/onnx.git
 cd onnx
 git submodule update --init --recursive
-python setup.py install
-```
-
-Note: When installing in a non-Anaconda environment, make sure to install the Protobuf compiler before running the pip installation of onnx. For example, on Ubuntu:
-
-```
-sudo apt-get install protobuf-compiler libprotoc-dev
-pip install onnx
+# prefer lite proto
+set CMAKE_ARGS=-DONNX_USE_LITE_PROTO=ON
+pip install -e .
 ```
 
-### Windows
-If you are building ONNX from source on Windows, it is recommended that you also build Protobuf locally as a static library. The version distributed with conda-forge is a DLL, but ONNX expects it to be a static library.
-
-Note that the instructions in this README assume you are using Visual Studio. It is recommended that you run all the commands from a shell started from "Developer Command Prompt for VS 2019" and keep the build system generator for cmake (e.g., cmake -G "Visual Studio 16 2019") consistent.
-
-#### Build Protobuf and ONNX on Windows
-Step 1: Build Protobuf locally
+### Building Protobuf from source
+* **Windows**
 ```
 git clone https://github.com/protocolbuffers/protobuf.git
 cd protobuf
 git checkout v3.11.3
 cd cmake
-# Explicitly set -Dprotobuf_MSVC_STATIC_RUNTIME=OFF to make sure protobuf does not statically link to runtime library
-cmake -G -A -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=<protobuf_install_dir>
-# For example:
-# cmake -G "Visual Studio 16 2019" -A x64 -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=..\install
+cmake -G "Visual Studio 16 2019" -A $arch -DCMAKE_INSTALL_PREFIX=<protobug_install_dir> -DCMAKE_BUILD_TYPE=Release -Dprotobuf_MSVC_STATIC_RUNTIME=ON -DProtobuf_USE_STATIC_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF .
path: README.md
text: @user1:
I see that protobuf_MSVC_STATIC_RUNTIME changed from OFF to ON in the instructions. Does that actually work? I thought it had to be set to OFF and in our environment that's how we build it.

@author:
I changed the instructions to match the current onnx release package config... Linking statically to runtime works as long as we are not building shared lib

diff_hunk: @@ -50,116 +50,83 @@ Stay up to date with the latest ONNX news. [[Facebook](https://www.facebook.com/
 
 # Installation
 
-## Binaries
-
-A binary build of ONNX is available from [Conda](https://conda.io), in [conda-forge](https://conda-forge.org/):
-
+## Official Python packages
+ONNX released packages are published in PyPi.
 ```
-conda install -c conda-forge onnx
+pip install numpy protobuf==3.11.3
+pip install onnx
 ```
 
-## Source
-
-If you have installed onnx on your machine, please `pip uninstall onnx` first before the following process of build from source.
+[Weekly packages](https://test.pypi.org/project/onnx-weekly/) are published in test pypi to enable experimentation and early testing.
 
-### Linux and MacOS
-You will need an install of Protobuf and NumPy to build ONNX.  One easy
-way to get these dependencies is via
-[Anaconda](https://www.anaconda.com/download/):
 
+## Conda packages
+A binary build of ONNX is available from [Conda](https://conda.io), in [conda-forge](https://conda-forge.org/):
 ```
-# Use conda-forge protobuf, as default doesn't come with protoc
-conda install -c conda-forge protobuf numpy
+conda install -c conda-forge numpy protobuf==3.11.3 libprotobuf=3.11.3
+conda install -c conda-forge onnx
 ```
 
-You can then install ONNX from PyPi (Note: Set environment variable `ONNX_ML=1` for onnx-ml):
+You can also use the [onnx-dev docker image](https://hub.docker.com/r/onnx/onnx-dev) for a Linux-based installation without having to worry about dependency versioning.
 
-```
-pip install onnx
-```
 
-Alternatively, you can also build and install ONNX locally from source code:
+## Build ONNX from Source
+Before building from source uninstall any existing versions of onnx `pip uninstall onnx`.  
+If you are building ONNX from source, it is recommended that you also build Protobuf locally as a static library. Specifically on Windows, the version distributed with conda-forge is a DLL, but ONNX expects it to be a static library. Building protobuf locally also let's you control the verison of protobuf. The tested and recommended version is 3.11.3.
 
+Note for Windows : The instructions in this README assume you are using Visual Studio. It is recommended that you run all the commands from a shell started from "Developer Command Prompt for VS 2019" and keep the build system generator for cmake (e.g., cmake -G "Visual Studio 16 2019") consistent while building protobuf as well as ONNX.
 ```
 git clone https://github.com/onnx/onnx.git
 cd onnx
 git submodule update --init --recursive
-python setup.py install
-```
-
-Note: When installing in a non-Anaconda environment, make sure to install the Protobuf compiler before running the pip installation of onnx. For example, on Ubuntu:
-
-```
-sudo apt-get install protobuf-compiler libprotoc-dev
-pip install onnx
+# prefer lite proto
+set CMAKE_ARGS=-DONNX_USE_LITE_PROTO=ON
+pip install -e .
 ```
 
-### Windows
-If you are building ONNX from source on Windows, it is recommended that you also build Protobuf locally as a static library. The version distributed with conda-forge is a DLL, but ONNX expects it to be a static library.
-
-Note that the instructions in this README assume you are using Visual Studio. It is recommended that you run all the commands from a shell started from "Developer Command Prompt for VS 2019" and keep the build system generator for cmake (e.g., cmake -G "Visual Studio 16 2019") consistent.
-
-#### Build Protobuf and ONNX on Windows
-Step 1: Build Protobuf locally
+### Building Protobuf from source
+* **Windows**
 ```
 git clone https://github.com/protocolbuffers/protobuf.git
 cd protobuf
 git checkout v3.11.3
 cd cmake
-# Explicitly set -Dprotobuf_MSVC_STATIC_RUNTIME=OFF to make sure protobuf does not statically link to runtime library
-cmake -G -A -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=<protobuf_install_dir>
-# For example:
-# cmake -G "Visual Studio 16 2019" -A x64 -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=..\install
+cmake -G "Visual Studio 16 2019" -A $arch -DCMAKE_INSTALL_PREFIX=<protobug_install_dir> -DCMAKE_BUILD_TYPE=Release -Dprotobuf_MSVC_STATIC_RUNTIME=ON -DProtobuf_USE_STATIC_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF .
path: README.md
text: @user1:
protobuf_USE_STATIC_LIBS is not valid for the command for building protobuf. The correct setting is: ```protobuf_BUILD_SHARED_LIBS=OFF```