diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -514,6 +514,16 @@
             f.write('docs = ')
             f.write(out)
 
+# ws2:longPathAware increases MAX_PATH on Windows 10 Anniversary Edition and
+# newer to larger than its default of 260.
+HGEXE_MANIFEST = '''
+<application xmlns="urn:schemas-microsoft-com:asm.v3">
+    <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
+        <ws2:longPathAware>true</ws2:longPathAware>
+    </windowsSettings>
+</application>
+'''.strip()
+
 class buildhgexe(build_ext):
     description = 'compile hg.exe from mercurial/exewrapper.c'
 
@@ -556,11 +566,20 @@
             f.write('#define HGPYTHONLIB "%s"\n' % pythonlib)
         objects = self.compiler.compile(['mercurial/exewrapper.c'],
                                          output_dir=self.build_temp)
-        dir = os.path.dirname(self.get_ext_fullpath('dummy'))
-        target = os.path.join(dir, 'hg')
-        self.compiler.link_executable(objects, target,
-                                      libraries=[],
-                                      output_dir=self.build_temp)
+
+        try:
+            fd, manifestpath = tempfile.mkstemp('.manifest')
+            fd.write(HGEXE_MANIFEST)
+            fd.close()
+
+            dir = os.path.dirname(self.get_ext_fullpath('dummy'))
+            target = os.path.join(dir, 'hg')
+
+            self.compiler.link_executable(objects, target,
+                libraries=[], output_dir=self.build_temp,
+                extra_postargs=['/MANIFESTFILE:%s' % manifestpath])
+        finally:
+            os.unlink(manifestpath)
 
     @property
     def hgexepath(self):