Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
6f2bc19b
Commit
6f2bc19b
authored
Apr 08, 2015
by
Kun Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cross-compilation for Windows on Linux using MinGW. Check library dependencies of artifact
parent
c6792363
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
12 deletions
+70
-12
build-protoc.sh
protoc-artifacts/build-protoc.sh
+70
-12
No files found.
protoc-artifacts/build-protoc.sh
View file @
6f2bc19b
...
...
@@ -25,7 +25,8 @@ E_ASSERT_FAILED=99
# Usage:
fail
()
{
echo
"Error:
$1
"
echo
"ERROR:
$1
"
echo
exit
$E_ASSERT_FAILED
}
...
...
@@ -49,8 +50,11 @@ assertEq ()
# Usage: checkArch <path-to-protoc>
checkArch
()
{
echo
echo
"Checking for file format ..."
if
[[
"
$OS
"
==
windows
||
"
$OS
"
==
linux
]]
;
then
format
=
"
$(
objdump
-f
"
$1
"
|
grep
-o
"file format .*$"
|
grep
-o
"[^ ]*$"
)
"
echo
Format
=
$format
if
[[
"
$OS
"
==
linux
]]
;
then
if
[[
"
$ARCH
"
==
x86_32
]]
;
then
assertEq
$format
"elf32-i386"
$LINENO
...
...
@@ -71,6 +75,7 @@ checkArch ()
fi
elif
[[
"
$OS
"
==
osx
]]
;
then
format
=
"
$(
file
-b
"
$1
"
|
grep
-o
"[^ ]*$"
)
"
echo
Format
=
$format
if
[[
"
$ARCH
"
==
x86_32
]]
;
then
assertEq
$format
"i386"
$LINENO
elif
[[
"
$ARCH
"
==
x86_64
]]
;
then
...
...
@@ -79,8 +84,45 @@ checkArch ()
fail
"Unsupported arch:
$ARCH
"
fi
else
fail
"Unsupported system:
$
(
uname
)
"
fail
"Unsupported system:
$
OS
"
fi
echo
}
# Checks the dependencies of the artifact. Artifacts should only depend on
# system libraries.
# Usage: checkDependencies <path-to-protoc>
checkDependencies
()
{
if
[[
"
$OS
"
==
windows
]]
;
then
dump_cmd
=
'objdump -x '
"
$1
"
' | fgrep "DLL Name"'
white_list
=
"KERNEL32
\.
dll
\|
msvcrt
\.
dll"
elif
[[
"
$OS
"
==
linux
]]
;
then
dump_cmd
=
'ldd '
"
$1
"
if
[[
"
$ARCH
"
==
x86_32
]]
;
then
white_list
=
"linux-gate
\.
so
\.
1
\|
libpthread
\.
so
\.
0
\|
libm
\.
so
\.
6
\|
libc
\.
so
\.
6
\|
ld-linux
\.
so
\.
2"
elif
[[
"
$ARCH
"
==
x86_64
]]
;
then
white_list
=
"linux-vdso
\.
so
\.
1
\|
libpthread
\.
so
\.
0
\|
libm
\.
so
\.
6
\|
libc
\.
so
\.
6
\|
ld-linux-x86-64
\.
so
\.
2"
fi
elif
[[
"
$OS
"
==
osx
]]
;
then
dump_cmd
=
'otool -L '
"
$1
"
white_list
=
"libz
\.
1
\.
dylib
\|
libc++
\.
1
\.
dylib
\|
libSystem
\.
B
\.
dylib"
fi
if
[[
-z
"
$white_list
"
||
-z
"
$dump_cmd
"
]]
;
then
fail
"Unsupported platform
$OS
-
$ARCH
."
fi
echo
"Checking for expected dependencies ..."
eval
$dump_cmd
|
grep
-i
"
$white_list
"
||
fail
"doesn't show any expected dependencies"
echo
"Checking for unexpected dependencies ..."
eval
$dump_cmd
|
grep
-i
-v
"
$white_list
"
ret
=
$?
if
[[
$ret
==
0
]]
;
then
fail
"found unexpected dependencies (listed above)."
elif
[[
$ret
!=
1
]]
;
then
fail
"Error when checking dependencies."
fi
# grep returns 1 when "not found", which is what we expect
echo
"Dependencies look good."
echo
}
############################################################################
...
...
@@ -100,6 +142,7 @@ fi
# Override the default value set in configure.ac that has '-g' which produces
# huge binary.
CXXFLAGS
=
"-DNDEBUG"
LDFLAGS
=
""
if
[[
"
$(
uname
)
"
==
CYGWIN
*
]]
;
then
assertEq
"
$OS
"
windows
$LINENO
...
...
@@ -116,13 +159,28 @@ elif [[ "$(uname)" == MINGW32* ]]; then
assertEq
"
$OS
"
windows
$LINENO
assertEq
"
$ARCH
"
x86_32
$LINENO
elif
[[
"
$(
uname
)
"
==
Linux
*
]]
;
then
assertEq
"
$OS
"
linux
$LINENO
if
[[
"
$ARCH
"
==
x86_64
]]
;
then
CXXFLAGS
=
"
$CXXFLAGS
-m64"
elif
[[
"
$ARCH
"
==
x86_32
]]
;
then
CXXFLAGS
=
"
$CXXFLAGS
-m32"
if
[[
"
$OS
"
==
linux
]]
;
then
if
[[
"
$ARCH
"
==
x86_64
]]
;
then
CXXFLAGS
=
"
$CXXFLAGS
-m64"
elif
[[
"
$ARCH
"
==
x86_32
]]
;
then
CXXFLAGS
=
"
$CXXFLAGS
-m32"
else
fail
"Unsupported arch:
$ARCH
"
fi
elif
[[
"
$OS
"
==
windows
]]
;
then
# Cross-compilation for Windows
# TODO(zhangkun83) MinGW 64 always adds dependency on libwinpthread-1.dll,
# which is undesirable for repository deployment.
CONFIGURE_ARGS
=
"
$CONFIGURE_ARGS
"
if
[[
"
$ARCH
"
==
x86_64
]]
;
then
CONFIGURE_ARGS
=
"
$CONFIGURE_ARGS
--host=x86_64-w64-mingw32"
elif
[[
"
$ARCH
"
==
x86_32
]]
;
then
CONFIGURE_ARGS
=
"
$CONFIGURE_ARGS
--host=i686-w64-mingw32"
else
fail
"Unsupported arch:
$ARCH
"
fi
else
fail
"
Unsupported arch:
$ARCH
"
fail
"
Cannot build
$OS
on
$(
uname
)
"
fi
elif
[[
"
$(
uname
)
"
==
Darwin
*
]]
;
then
assertEq
"
$OS
"
osx
$LINENO
...
...
@@ -137,19 +195,19 @@ else
fail
"Unsupported system:
$(
uname
)
"
fi
export
CXXFLAGS
# Statically link libgcc and libstdc++.
# -s to produce stripped binary.
# And they don't work under Mac.
if
[[
"
$OS
"
!=
osx
]]
;
then
export
LDFLAGS
=
"
-static-libgcc -static-libstdc++ -s"
LDFLAGS
=
"
$LDFLAGS
-static-libgcc -static-libstdc++ -s"
fi
export
CXXFLAGS LDFLAGS
TARGET_FILE
=
target/protoc.exe
cd
"
$WORKING_DIR
"
/..
&&
./configure
$CONFIGURE_ARGS
&&
cd
src
&&
make clean
&&
make
$MAKE_TARGET
&&
cd
"
$WORKING_DIR
"
&&
mkdir
-p
target
&&
(
cp
../src/protoc
$TARGET_FILE
||
cp
../src/protoc.exe
$TARGET_FILE
)
&&
checkArch
$TARGET_FILE
checkArch
$TARGET_FILE
&&
checkDependencies
$TARGET_FILE
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment