index.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. .. _webidl:
  2. ======
  3. WebIDL
  4. ======
  5. WebIDL describes interfaces web browsers are supposed to implement.
  6. The interaction between WebIDL and the build system is somewhat complex.
  7. This document will attempt to explain how it all works.
  8. Overview
  9. ========
  10. ``.webidl`` files throughout the tree define interfaces the browser
  11. implements. Since Gecko/Firefox is implemented in C++, there is a
  12. mechanism to convert these interfaces and associated metadata to
  13. C++ code. That's where the build system comes into play.
  14. All the code for interacting with ``.webidl`` files lives under
  15. ``dom/bindings``. There is code in the build system to deal with
  16. WebIDLs explicitly.
  17. WebIDL source file flavors
  18. ==========================
  19. Not all ``.webidl`` files are created equal! There are several flavors,
  20. each represented by a separate symbol from :ref:`mozbuild_symbols`.
  21. WEBIDL_FILES
  22. Refers to regular/static ``.webidl`` files. Most WebIDL interfaces
  23. are defined this way.
  24. GENERATED_EVENTS_WEBIDL_FILES
  25. In addition to generating a binding, these ``.webidl`` files also
  26. generate a source file implementing the event object in C++
  27. PREPROCESSED_WEBIDL_FILES
  28. The ``.webidl`` files are generated by preprocessing an input file.
  29. They otherwise behave like *WEBIDL_FILES*.
  30. TEST_WEBIDL_FILES
  31. Like *WEBIDL_FILES* but the interfaces are for testing only and
  32. aren't shipped with the browser.
  33. PREPROCESSED_TEST_WEBIDL_FILES
  34. Like *TEST_WEBIDL_FILES* except the ``.webidl`` is obtained via
  35. preprocessing, much like *PREPROCESSED_WEBIDL_FILES*.
  36. GENERATED_WEBIDL_FILES
  37. The ``.webidl`` for these is obtained through an *external*
  38. mechanism. Typically there are custom build rules for producing these
  39. files.
  40. Producing C++ code
  41. ==================
  42. The most complicated part about WebIDLs is the process by which
  43. ``.webidl`` files are converted into C++.
  44. This process is handled by code in the :py:mod:`mozwebidlcodegen`
  45. package. :py:class:`mozwebidlcodegen.WebIDLCodegenManager` is
  46. specifically where you want to look for how code generation is
  47. performed. This includes complex dependency management.
  48. Requirements
  49. ============
  50. This section aims to document the build and developer workflow requirements
  51. for WebIDL.
  52. Parser unit tests
  53. There are parser tests provided by ``dom/bindings/parser/runtests.py``
  54. that should run as part of ``make check``. There must be a mechanism
  55. to run the tests in *human* mode so they output friendly error
  56. messages.
  57. The current mechanism for this is ``mach webidl-parser-test``.
  58. Mochitests
  59. There are various mochitests under ``dom/bindings/test``. They should
  60. be runnable through the standard mechanisms.
  61. Working with test interfaces
  62. ``TestExampleGenBinding.cpp`` calls into methods from the
  63. ``TestExampleInterface``, ``TestExampleProxyInterface``,
  64. and ``TestExampleWorkerInterface`` interfaces.
  65. These interfaces need to be generated as part of the build. These
  66. interfaces should not be exported or packaged.
  67. There is a ``compiletests`` make target in ``dom/bindings`` that
  68. isn't part of the build that facilitates turnkey code generation
  69. and test file compilation.
  70. Minimal rebuilds
  71. Reprocessing every output for every change is expensive. So we don't
  72. inconvenience people changing ``.webidl`` files, the build system
  73. should only perform a minimal rebuild when sources change.
  74. This logic is mostly all handled in
  75. :py:class:`mozwebidlcodegen.WebIDLCodegenManager`. The unit tests for
  76. that Python code should adequately test typical rebuild scenarios.
  77. Bug 940469 tracks making the existing implementation better.
  78. Explicit method for performing codegen
  79. There needs to be an explicit method for invoking code generation.
  80. It needs to cover regular and test files.
  81. This is implemented via ``make export`` in ``dom/bindings``.
  82. No-op binding generation should be fast
  83. So developers touching ``.webidl`` files are not inconvenienced,
  84. no-op binding generation should be fast. Watch out for the build system
  85. processing large dependency files it doesn't need in order to perform
  86. code generation.
  87. Ability to generate example files
  88. *Any* interface can have example ``.h``/``.cpp`` files generated.
  89. There must be a mechanism to facilitate this.
  90. This is currently facilitated through ``mach webidl-example``. e.g.
  91. ``mach webidl-example HTMLStyleElement``.