rpwoodbu / mosh-chrome

Mosh for Chrome
GNU General Public License v3.0
371 stars 59 forks source link

shrink extension downloads by using CWS's arch filtering feature #170

Open vapier opened 6 years ago

vapier commented 6 years ago

currently the chrome app shipped to end users include all nexe files for all architectures which can waste ~10MB of disk (and whatever network transfer overhead)

the manifest.json format actually offers a solution specifically for this:

Name Value
nacl_arch x86-64, x86-32, or arm
sub_package_path the path of the directory (starting with _platform_specific) that contains the files for the designated NaCl architecture

and offers an example manifest.json:

  "platforms": [
    {
      "nacl_arch": "x86-64",
      "sub_package_path": "_platform_specific/x86-64/"
    },
    {
      "nacl_arch": "x86-32",
      "sub_package_path": "_platform_specific/x86-32/"
    },
    {
      "nacl_arch": "arm",
      "sub_package_path": "_platform_specific/arm/"
    },
    {
      "sub_package_path": "_platform_specific/all/"
    }
  ]

the docs there are a bit light on details as to the requirements of these fields, but having done some experiments with other apps (and read a bit of the server side CWS code), i think the only requirement is that sub_package_path be a directory. so if you want to keep most everything in the top level:

./
  |-- mosh_client_manifest_all_architectures.nmf
  |-- arm/
  |     `-- mosh_client_armv7.nexe
  |-- x86-32/
  |     `-- mosh_client_i686.nexe
  `-- x86-64/
        `-- mosh_client_x86_64.nexe

then the mosh_client_manifest_all_architectures.nmf would read:

{
  "files": {},
  "program": {
    "x86-64": {
      "url": "x86-64/mosh_client_x86_64.nexe"
    },
    "arm": {
      "url": "arm/mosh_client_armv7.nexe"
    },
    "x86-32": {
      "url": "x86-32/mosh_client_i686.nexe"
    }
  }
}

then you'd add this snippet to manifest.json:

  "platforms": [
    {
      "nacl_arch": "x86-64",
      "sub_package_path": "x86-64/"
    },
    {
      "nacl_arch": "x86-32",
      "sub_package_path": "x86-32/"
    },
    {
      "nacl_arch": "arm",
      "sub_package_path": "arm/"
    }
  ]

then when users install the extension, CWS would detect the architecture of the client and automatically elide unsupported architectures. so on my arm system, i would only have the arm/ subdir ... x86-32/ and x86-64/ wouldn't exist.

with my suggested layout above, i don't think you'd need to change any of the existing JS or HTML code. only update the nacl related bits.

rpwoodbu commented 6 years ago

I didn't know about this. Definitely worth doing! Shouldn't be hard at all. Thanks for the detailed write-up.

Assigning to myself for now, but if you want to undertake this, let me know.

vapier commented 6 years ago

i wrote a python script that might simplify things: https://chromium-review.googlesource.com/c/apps/libapps/+/843816/1/libdot/bin/plugin-to-platform-specific.py

once the manifest & nexe's have been created, run it against the app output dir:

$ .../plugin-to-platform-specific.py --output $OUTPUT/_platform_specific --input $OUTPUT

that'll rewrite the nmf file for you and relocate all the nexe files to the appropriate _platform_specific/ subdir.