17
17
// along with hidapi_rust. If not, see <http://www.gnu.org/licenses/>.
18
18
// *************************************************************************
19
19
20
+ extern crate autotools;
20
21
extern crate cc;
21
22
22
23
use std:: process:: Command ;
23
24
use std:: env;
24
-
25
- // Copy-pasted from `https://github.com/paritytech/parity-ethereum/blob/cb03f380ab2bb37ff18771e6886c42098ad8b15a/docker/android/Dockerfile#L44-L62`
26
- const ANDROID_CFG : [ & str ; 5 ] = [
27
- "git checkout 83d918449f22720d84a341a05e24b6d109e6d3ae" ,
28
- "git apply ../libudev.patch" ,
29
- "./autogen.sh" ,
30
- "./configure --disable-introspection --disable-programs --disable-hwdb --host=arm-linux-androideabi --prefix=/opt/ndk-standalone/sysroot/usr/ --enable-shared=false" ,
31
- "make"
32
- ] ;
33
-
34
- const LINUX_CFG : [ & str ; 3 ] = [
35
- "./autogen.sh" ,
36
- "./configure" ,
37
- "make"
38
- ] ;
25
+ use std:: path:: Path ;
39
26
40
27
fn main ( ) {
41
28
let target = env:: var ( "TARGET" ) . unwrap ( ) ;
@@ -57,53 +44,90 @@ fn main() {
57
44
println ! ( "cargo:rustc-link-lib=framework=CoreFoundation" ) ;
58
45
59
46
} else if target. contains ( "android" ) {
60
- set_android_flags ( ) ;
61
- execute_shell_cmd ( & ANDROID_CFG ) ;
47
+ enable_android_hack ( ) ;
48
+ env:: set_var ( "CXX" , "arm-linux-androideabi-clang++" ) ;
49
+ env:: set_var ( "CC" , "arm-linux-androideabi-gcc" ) ;
50
+ let libudev = autotools:: Config :: new ( "etc/eudev" )
51
+ // -s: make symlinks
52
+ // -m: build if it applicable
53
+ // -i: install
54
+ // -v: verbose
55
+ // -f: consider all files obsolete
56
+ . reconf ( "-smivf" )
57
+ . insource ( true )
58
+ . host ( "arm-linux-androideabi" )
59
+ . disable_shared ( )
60
+ . disable ( "-introspection" , None )
61
+ . disable ( "-programs" , None )
62
+ . disable ( "-hwdb" , None )
63
+ . cflag ( "-D LINE_MAX=2048" )
64
+ . cflag ( "-D RLIMIT_NLIMITS=15" )
65
+ . cflag ( "-D IPTOS_LOWCOST=2" )
66
+ . cflag ( "-std=gnu99" )
67
+ . build ( ) ;
68
+
69
+ disable_android_hack ( ) ;
70
+
62
71
let mut config = cc:: Build :: new ( ) ;
63
72
config. file ( "etc/hidapi/linux/hid.c" ) . include ( "etc/hidapi/hidapi" ) ;
64
73
config. compile ( "libhidapi.a" ) ;
65
74
66
- println ! ( "cargo:rustc-link-search=native=./etc/eudev/ src/libudev/.libs" ) ;
75
+ println ! ( "cargo:rustc-link-search=native={}/ src/libudev/.libs" , libudev . display ( ) ) ;
67
76
println ! ( "cargo:rustc-link-lib=static=udev" ) ;
68
77
} else if target. contains ( "linux" ) {
69
- execute_shell_cmd ( & LINUX_CFG ) ;
70
- let mut config = cc:: Build :: new ( ) ;
71
- config. file ( "etc/hidapi/linux/hid.c" ) . include ( "etc/hidapi/hidapi" ) ;
72
- config. compile ( "libhidapi.a" ) ;
73
78
74
- println ! ( "cargo:rustc-link-search=native=./etc/eudev/src/libudev/.libs" ) ;
79
+ let libudev = autotools:: Config :: new ( "etc/eudev" )
80
+ // -s: make symlinks
81
+ // -m: build if it applicable
82
+ // -i: install
83
+ // -v: verbose
84
+ // -f: consider all files obsolete
85
+ . reconf ( "-smivf" )
86
+ . insource ( true )
87
+ . disable_shared ( )
88
+ . build ( ) ;
89
+
90
+ cc:: Build :: new ( )
91
+ . file ( "etc/hidapi/linux/hid.c" )
92
+ . include ( "etc/hidapi/hidapi" )
93
+ . compile ( "libhidapi.a" ) ;
94
+
95
+ println ! ( "cargo:rustc-link-search=native={}/src/libudev/.libs" , libudev. display( ) ) ;
75
96
println ! ( "cargo:rustc-link-lib=static=udev" ) ;
76
97
}
77
98
}
78
99
79
- fn set_android_flags ( ) {
80
- env:: set_var ( "CFLAGS" , "-D LINE_MAX=2048 -D RLIMIT_NLIMITS=15 -D IPTOS_LOWCOST=2 -std=gnu99" ) ;
81
- env:: set_var ( "CXX" , "arm-linux-androideabi-clang++" ) ;
82
- env:: set_var ( "CC" , "arm-linux-androideabi-gcc" ) ;
83
- }
100
+ fn enable_android_hack ( ) {
101
+ env:: set_current_dir ( Path :: new ( "etc/eudev" ) )
102
+ . expect ( "Could not find the directory: \" etc\\ eudev\" " ) ;
84
103
85
- fn execute_shell_cmd ( commands : & [ & str ] ) {
86
- let start = std :: env :: current_dir ( ) . expect ( "Couldn't fetch current directory" ) ;
87
- let target = std :: path :: Path :: new ( & start ) . join ( "etc/eudev" ) ;
88
- env :: set_current_dir ( target ) . expect ( "Could not find the directory: \" etc \\ eudev \" " ) ;
104
+ Command :: new ( "git" )
105
+ . args ( & [ "checkout" , "83d918449f22720d84a341a05e24b6d109e6d3ae" ] )
106
+ . status ( )
107
+ . expect ( "git checkout failed " ) ;
89
108
90
- for full_cmd in commands. iter ( ) {
91
- let ignore_error = full_cmd. starts_with ( "git" ) && full_cmd. contains ( "apply" ) ;
109
+ Command :: new ( "git" )
110
+ . args ( & [ "apply" , "../libudev.patch" ] )
111
+ . status ( )
112
+ . expect ( "git apply etc/libudev.patch failed" ) ;
92
113
93
- let mut it = full_cmd. split_whitespace ( ) ;
94
- let cmd = it. next ( ) . expect ( "A command should have at least one element; qed" ) ;
114
+ env:: set_current_dir ( Path :: new ( "../.." ) )
115
+ . expect ( "Could not find the directory: \" etc\\ eudev\" " ) ;
116
+ }
95
117
96
- let this_cmd = Command :: new ( cmd)
97
- . args ( it)
98
- . status ( )
99
- . expect ( & format ! ( "Command {} failed" , cmd) ) ;
118
+ fn disable_android_hack ( ) {
119
+ env:: set_current_dir ( Path :: new ( "etc/eudev" ) )
120
+ . expect ( "Could not find the directory: \" etc\\ eudev\" " ) ;
100
121
101
- if !this_cmd. success ( ) && !ignore_error {
102
- panic ! ( "{}" , this_cmd) ;
103
- } else if ignore_error {
104
- println ! ( "IGNORED \" git apply error\" {}" , this_cmd) ;
105
- }
106
- }
122
+ Command :: new ( "git" )
123
+ . args ( & [ "apply" , "-R" , "../libudev.patch" ] )
124
+ . status ( )
125
+ . expect ( "git revert patch failed" ) ;
126
+ Command :: new ( "git" )
127
+ . args ( & [ "checkout" , "master" ] )
128
+ . status ( )
129
+ . expect ( "git checkout master failed" ) ;
107
130
108
- env:: set_current_dir ( start) . expect ( "Couldn't go back to start directory" ) ;
131
+ env:: set_current_dir ( Path :: new ( "../.." ) )
132
+ . expect ( "Could not find the directory: \" etc\\ eudev\" " ) ;
109
133
}
0 commit comments