mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #8288 - larsbergstrom:new_android_build, r=mbrubeck
New Android suppport r/f? @mbrubeck No need to r+ urgently; I want to do a little bit more testing of the release build, but I'm hoping to land this bit (moving to a more sane build process) next week. The new version of building an APK: 1) Removes the glutin-based APK builder from the link step 2) Adds a build.rs step to the build of the final Servo library that adds the native code required by glutin's android_rs_glue (e.g., `ANativeActivity_onCreate` definition) 3) Replaces the link step with a `fake-ld.sh` script that instead creates a libservo.so 4) Adds a new mach `package` step to build the APK that has some Rust code that builds the library from a set of in-tree build files This setup fixes a number of problems: 1) We can use gdb, because we use `ndk-build`, which adds the .gdbserver info, plus we keep around all of the build files (also required by the ndk gdb) 2) We can add more Java code & hooks to handle Android intents 3) We no longer have any git submodules or the awkward two-step build with android-rs-glue Many other setups were tried (and failed). The most obvious ones is building a libservo.so from a `dylib` target from the servo build on Android. This doesn't work because you can't have a different default lib target on one platform than others in Cargo, and you also can't pass it in from the commandline (e.g., --lib does not have a dylib arg). Additionally, if you don't go through the intermediate libservo.rlib step (which removes unused symbols), then you end up with a TON of missing symbols because our -sys crates are super sloppy about that. I spent a few weeks beginning to clean them up, but since it's something we can't easily enforce (and new -sys packages will have this problem, too, since it's only an issue with the Android loader), it made more sense to me to just have the build set up to discard those unused bits of code before they ever get to the linker, much less the loader. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8288) <!-- Reviewable:end -->
This commit is contained in:
commit
0699d38e80
25 changed files with 657 additions and 29 deletions
|
@ -198,13 +198,6 @@ class MachCommands(CommandBase):
|
|||
if verbose:
|
||||
opts += ["-v"]
|
||||
if android:
|
||||
# Ensure the APK builder submodule has been built first
|
||||
apk_builder_dir = "support/android-rs-glue"
|
||||
with cd(path.join(apk_builder_dir, "apk-builder")):
|
||||
status = call(["cargo", "build"], env=self.build_env(), verbose=verbose)
|
||||
if status:
|
||||
return status
|
||||
|
||||
opts += ["--target", "arm-linux-androideabi"]
|
||||
|
||||
if debug_mozjs or self.config["build"]["debug-mozjs"]:
|
||||
|
|
|
@ -135,6 +135,9 @@ class CommandBase(object):
|
|||
self._cargo_build_id = f.read().strip()
|
||||
return self._cargo_build_id
|
||||
|
||||
def get_top_dir(self):
|
||||
return self.context.topdir
|
||||
|
||||
def get_target_dir(self):
|
||||
if "CARGO_TARGET_DIR" in os.environ:
|
||||
return os.environ["CARGO_TARGET_DIR"]
|
||||
|
|
|
@ -22,7 +22,7 @@ from mach.decorators import (
|
|||
Command,
|
||||
)
|
||||
|
||||
from servo.command_base import CommandBase
|
||||
from servo.command_base import CommandBase, cd
|
||||
|
||||
|
||||
def read_file(filename, if_exists=False):
|
||||
|
@ -33,8 +33,7 @@ def read_file(filename, if_exists=False):
|
|||
|
||||
|
||||
@CommandProvider
|
||||
class MachCommands(CommandBase):
|
||||
|
||||
class PostBuildCommands(CommandBase):
|
||||
@Command('run',
|
||||
description='Run Servo',
|
||||
category='post-build')
|
||||
|
@ -167,3 +166,36 @@ class MachCommands(CommandBase):
|
|||
import webbrowser
|
||||
webbrowser.open("file://" + path.abspath(path.join(
|
||||
self.get_target_dir(), "doc", "servo", "index.html")))
|
||||
|
||||
@Command('package',
|
||||
description='Package Servo (currently, Android APK only)',
|
||||
category='post-build')
|
||||
@CommandArgument('--release', '-r', action='store_true',
|
||||
help='Package the release build')
|
||||
@CommandArgument('--dev', '-d', action='store_true',
|
||||
help='Package the dev build')
|
||||
@CommandArgument(
|
||||
'params', nargs='...',
|
||||
help="Command-line arguments to be passed through to Servo")
|
||||
def package(self, params, release=False, dev=False, debug=False, debugger=None):
|
||||
env = self.build_env()
|
||||
target_dir = path.join(self.get_target_dir(), "arm-linux-androideabi")
|
||||
dev_flag = ""
|
||||
|
||||
if dev:
|
||||
env["NDK_DEBUG"] = "1"
|
||||
env["ANT_FLAVOR"] = "debug"
|
||||
dev_flag = "-d"
|
||||
target_dir = path.join(target_dir, "debug")
|
||||
else:
|
||||
env["ANT_FLAVOR"] = "release"
|
||||
target_dir = path.join(target_dir, "release")
|
||||
|
||||
output_apk = path.join(target_dir, "servo.apk")
|
||||
try:
|
||||
with cd(path.join("support", "android", "build-apk")):
|
||||
subprocess.check_call(["cargo", "run", "--", dev_flag, "-o", output_apk, "-t", target_dir,
|
||||
"-r", self.get_top_dir()], env=env)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Packaging Android exited with return value %d" % e.returncode)
|
||||
return e.returncode
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue