@@ -168,13 +168,16 @@ fn build_android_dynamic_lib(daita: bool) -> anyhow::Result<()> {
168
168
let target_triple = env:: var ( "TARGET" ) . context ( "Missing 'TARGET'" ) ?;
169
169
let target = AndroidTarget :: from_str ( & target_triple) ?;
170
170
171
- // TODO: Since `libwg.so` is always copied to `android_output_path`, this rerun-directive will
172
- // always trigger cargo to rebuild this crate. Some mechanism to detected changes to `android_output_path`
173
- // is needed, because some external program may clean it at any time (e.g. gradle).
171
+ // This will either trigger a rebuild if any changes have been made to the libwg code
172
+ // or if the libwg.so file has been changed. The latter is required since the
173
+ // libwg.so file could be deleted. It however means that this build will need
174
+ // to run two times before it is properly cached.
175
+ // FIXME: Figure out a way to do this better. This is tracked in DROID-1697.
174
176
println ! (
175
177
"cargo::rerun-if-changed={}" ,
176
- android_output_path( target) ?. display( )
178
+ android_output_path( target) ?. join ( "libwg.so" ) . display( )
177
179
) ;
180
+ println ! ( "cargo::rerun-if-changed={}" , libwg_path( ) ?. display( ) ) ;
178
181
179
182
// Before calling `canonicalize`, the directory we're referring to actually has to exist.
180
183
std:: fs:: create_dir_all ( "../build" ) ?;
@@ -229,12 +232,15 @@ fn android_move_binary(binary: &Path, output: &Path) -> anyhow::Result<()> {
229
232
) ) ?;
230
233
std:: fs:: create_dir_all ( parent_of_output) ?;
231
234
232
- let mut move_command = Command :: new ( "mv" ) ;
233
- move_command
235
+ let mut copy_command = Command :: new ( "cp" ) ;
236
+ // -p command is required to preserve ownership and timestamp of the file to prevent a
237
+ // rebuild of this module every time.
238
+ copy_command
239
+ . arg ( "-p" )
234
240
. arg ( binary. to_str ( ) . unwrap ( ) )
235
241
. arg ( output. to_str ( ) . unwrap ( ) ) ;
236
242
237
- exec ( & mut move_command ) ?;
243
+ exec ( & mut copy_command ) ?;
238
244
239
245
Ok ( ( ) )
240
246
}
@@ -273,12 +279,20 @@ fn android_arch_name(target: AndroidTarget) -> String {
273
279
274
280
// Returns the path where the Android project expects Rust binaries to be
275
281
fn android_output_path ( target : AndroidTarget ) -> anyhow:: Result < PathBuf > {
276
- let relative_output_path = Path :: new ( "../android/app/build/extraJni" ) . join ( android_abi ( target) ) ;
282
+ let relative_output_path =
283
+ Path :: new ( "../android/app/build/rustJniLibs/android" ) . join ( android_abi ( target) ) ;
277
284
std:: fs:: create_dir_all ( relative_output_path. clone ( ) ) ?;
278
285
let output_path = relative_output_path. canonicalize ( ) ?;
279
286
Ok ( output_path)
280
287
}
281
288
289
+ // Return the path of the libwg folder so that we can trigger rebuilds when any code is
290
+ fn libwg_path ( ) -> anyhow:: Result < PathBuf > {
291
+ let relative_output_path = Path :: new ( "libwg" ) ;
292
+ let output_path = relative_output_path. canonicalize ( ) ?;
293
+ Ok ( output_path)
294
+ }
295
+
282
296
/// Execute a command, assert that it succeeds, and return stdout as a string.
283
297
fn exec ( mut command : impl BorrowMut < Command > ) -> anyhow:: Result < String > {
284
298
let command = command. borrow_mut ( ) ;
0 commit comments