diff --git a/.github/workflows/book.yml b/.github/workflows/book.yml index f71a091da..edf37a025 100644 --- a/.github/workflows/book.yml +++ b/.github/workflows/book.yml @@ -4,7 +4,7 @@ on: pull_request: push: branches: - - "master" + - "main" workflow_dispatch: jobs: @@ -27,7 +27,7 @@ jobs: - name: Deploy uses: peaceiris/actions-gh-pages@v4 - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./book/public diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f0498c8db..1eaa2a2ce 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -4,7 +4,7 @@ on: pull_request: push: branches: - - "master" + - "main" workflow_dispatch: jobs: @@ -24,7 +24,7 @@ jobs: - name: Deploy uses: peaceiris/actions-gh-pages@v4 - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./target/doc diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 1615c4cb3..6a8d3db59 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -6,7 +6,7 @@ on: - "*" push: branches: - - "master" + - "main" jobs: hygiene: @@ -132,7 +132,7 @@ jobs: uses: actions/checkout@v4 with: repository: gtk-rs/gir-files - ref: master + ref: main path: tests/gir-files - name: "Build (release)" uses: actions-rs/cargo@v1 @@ -148,7 +148,7 @@ jobs: uses: actions/checkout@v4 with: repository: gtk-rs/gtk4-rs - ref: master + ref: main path: gtk4-rs if: matrix.os == 'ubuntu-latest' - name: "Symlink `gir` in gtk4-rs" @@ -162,7 +162,7 @@ jobs: uses: actions/checkout@v4 with: repository: gtk-rs/gtk-rs-core - ref: master + ref: main path: gtk-rs-core if: matrix.os == 'ubuntu-latest' - name: "Symlink `gir` in gtk-rs-core" diff --git a/.github/workflows/typos.yaml b/.github/workflows/typos.yaml index 74d258d93..24309da9e 100644 --- a/.github/workflows/typos.yaml +++ b/.github/workflows/typos.yaml @@ -3,7 +3,7 @@ on: pull_request: push: branches: - - "master" + - "main" jobs: typos: name: Spell Check with Typos diff --git a/Cargo.lock b/Cargo.lock index 2d91e2de1..2be599dc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,21 +1,21 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "bitflags" -version = "2.6.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" [[package]] name = "clock_ticks" @@ -25,28 +25,28 @@ checksum = "c49a90f58e73ac5f41ed0ac249861ceb5f0976db35fabc2b9c2c856916042d63" [[package]] name = "env_filter" -version = "0.1.0" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" dependencies = [ - "log 0.4.22", + "log 0.4.25", ] [[package]] name = "env_logger" -version = "0.11.3" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +checksum = "dcaee3d8e3cfc3fd92428d477bc97fc29ec8716d180c0d74c643bb26166660e0" dependencies = [ "env_filter", - "log 0.4.22", + "log 0.4.25", ] [[package]] name = "equivalent" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "fix-getters-rules" @@ -75,7 +75,7 @@ dependencies = [ "fix-getters-rules", "getopts", "hprof", - "log 0.4.22", + "log 0.4.25", "regex", "rustdoc-stripper", "toml", @@ -84,9 +84,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "hprof" @@ -100,9 +100,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" dependencies = [ "equivalent", "hashbrown", @@ -114,50 +114,50 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" dependencies = [ - "log 0.4.22", + "log 0.4.25", ] [[package]] name = "log" -version = "0.4.22" +version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] [[package]] name = "regex" -version = "1.10.5" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -167,9 +167,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.5" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -178,9 +178,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rustdoc-stripper" @@ -189,18 +189,18 @@ source = "git+https://github.com/GuillaumeGomez/rustdoc-stripper#1170265c0f2a372 [[package]] name = "serde" -version = "1.0.195" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", @@ -209,18 +209,18 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.6" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] [[package]] name = "syn" -version = "2.0.48" +version = "2.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" dependencies = [ "proc-macro2", "quote", @@ -229,9 +229,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.14" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" +checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148" dependencies = [ "indexmap", "serde", @@ -242,18 +242,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.6" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.14" +version = "0.22.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" +checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" dependencies = [ "indexmap", "serde", @@ -264,27 +264,27 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "winnow" -version = "0.6.5" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "59690dea168f2198d1a3b0cac23b8063efcd11012f10ae4698f284808c8ef603" dependencies = [ "memchr", ] [[package]] name = "xml-rs" -version = "0.8.20" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193" +checksum = "c5b940ebc25896e71dd073bad2dbaa2abfe97b0a391415e22ad1326d9c54e3c4" diff --git a/book/book.toml b/book/book.toml index 3b7096400..99998bf65 100644 --- a/book/book.toml +++ b/book/book.toml @@ -6,5 +6,5 @@ src = "src" title = "Generate Rust bindings for GIR based libraries" [output.html] -git-repository-url = "https://github.com/gtk-rs/gir/tree/master/book" -edit-url-template = "https://github.com/gtk-rs/gir/edit/master/book/{path}" +git-repository-url = "https://github.com/gtk-rs/gir/tree/main/book" +edit-url-template = "https://github.com/gtk-rs/gir/edit/main/book/{path}" diff --git a/book/src/config/api.md b/book/src/config/api.md index d3e2704e0..c9607f54f 100644 --- a/book/src/config/api.md +++ b/book/src/config/api.md @@ -1,7 +1,7 @@ # API Options This mode requires you to write another TOML file. -[gtk/Gir.toml](https://github.com/gtk-rs/gtk/blob/master/Gir.toml) is a good example. +[gtk/Gir.toml](https://github.com/gtk-rs/gtk/blob/main/Gir.toml) is a good example. ```toml [options] @@ -298,8 +298,24 @@ version = "3.12" version = "3.18" ``` -For enumerations and bitflags, you can also configure additional `#[derive()]` -clauses optionally conditioned to a `cfg`. +For enumerations, bitflags and boxed types / records, you can configure +the `#[derive()]` clauses, optionally conditioned to a `cfg`. + +Providing `#[derive()]` clauses behaves differently depending on the type +they are added to: + +* for boxed types / records (except `inline_boxed` types), the provided + `#[derive()]` clauses replace all the derives that are normally added + by default (i.e. `#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]`); + if the default derives are needed, they must be explicitly listed. +* for `inline_boxed` types, only the `Debug` trait can be specified (and thus + added); providing any other trait will cause gir to fail with an error. +* for enumerations, the provided `#[derive()]` clauses replace all the ones + that are normally derived by default (i.e. `#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]`) + with the exception of `Copy` and `Clone` that are always derived; + if the default derives are needed, they must be explicitly listed. +* for bitflags, the provided `#[derive()]` clauses are simply added to + the derives implemented by default. ```toml [[object]] diff --git a/book/src/introduction.md b/book/src/introduction.md index 47b1ff0c2..966be75ce 100644 --- a/book/src/introduction.md +++ b/book/src/introduction.md @@ -40,7 +40,7 @@ Alternatively `--embed-docs` can be passed to prepare source-code for a document For a complete overview of available options, pass `--help`. ## GIR format reference -It can always be useful to look at the [reference](https://gi.readthedocs.io/en/latest/annotations/giannotations.html) or [schema](https://gitlab.gnome.org/GNOME/gobject-introspection/blob/master/docs/gir-1.2.rnc). +It can always be useful to look at the [reference](https://gi.readthedocs.io/en/latest/annotations/giannotations.html) or [schema](https://gitlab.gnome.org/GNOME/gobject-introspection/blob/main/docs/gir-1.2.rnc). ## Contact us If you use [gir] on another library and it fails and you can't figure out why, don't hesitate to [contact us](https://gtk-rs.org/contact)! diff --git a/book/src/tutorial/finding_gir_files.md b/book/src/tutorial/finding_gir_files.md index fb923a4d7..333dcf29f 100644 --- a/book/src/tutorial/finding_gir_files.md +++ b/book/src/tutorial/finding_gir_files.md @@ -19,7 +19,7 @@ In most cases it will be enough to follow the next two steps of the tutorial to If your library depends on GTK libraries, the recommended way to get the `.gir` files for them is to add the [gir-files repo](https://github.com/gtk-rs/gir-files) as a submodule as well. It's the recommended way, because some of the `.gir` files included in the libraries are invalid (missing or invalid annotations for example). These errors are already fixed in the gir files from the repo. -Otherwise you could use the above-mentioned methods to find the files and run the [script](https://github.com/gtk-rs/gir-files/blob/master/fix.sh) to fix the `.gir` files available in the gir-files repository (and only them!). +Otherwise you could use the above-mentioned methods to find the files and run the [script](https://github.com/gtk-rs/gir-files/blob/main/fix.sh) to fix the `.gir` files available in the gir-files repository (and only them!). You can run it like this (at the same level of the `.gir` files you want to patch): ```sh @@ -36,12 +36,12 @@ They can often be found in the repo containing the source of your dependencies o ## Example We want to generate the wrapper for pango. It is related to GTK, so in order to get its .gir files, we use the recommended way. -While being in the project folder `git-tutorial`, we add the [gir-files repo](https://github.com/gtk-rs/gir-files) as a submodule and set the branch of the submodule to master. +While being in the project folder `git-tutorial`, we add the [gir-files repo](https://github.com/gtk-rs/gir-files) as a submodule and set the branch of the submodule to main. ```sh git submodule add https://github.com/gtk-rs/gir-files git config -f .gitmodules submodule.gir-files.update none -git submodule set-branch --branch master -- ./gir-files +git submodule set-branch --branch main -- ./gir-files ``` We also change the setting so that the submodule is not automatically checked out, otherwise anyone using your library from git will have the useless submodule checked out. Run `git submodule update --checkout` if you want to update the submodule. diff --git a/book/src/tutorial/high_level_rust_api.md b/book/src/tutorial/high_level_rust_api.md index 96afeb939..471daa64e 100644 --- a/book/src/tutorial/high_level_rust_api.md +++ b/book/src/tutorial/high_level_rust_api.md @@ -114,11 +114,13 @@ v1_52 = ["ffi/v1_52", "v1_50"] The lib.rs file will not be replaced when you run gir. All the code that gir will generate for us is going to be in src/auto. We need to include all `auto` files in our library. +Also it needs to include sys create so auto files can use it. To do so, let's update the `src/lib.rs` file as follows: ```rust #![cfg_attr(docsrs, feature(doc_cfg))] +use ffi; pub use auto::*; mod auto; ``` diff --git a/book/src/tutorial/preparation.md b/book/src/tutorial/preparation.md index 62a31691a..d9f1e8148 100644 --- a/book/src/tutorial/preparation.md +++ b/book/src/tutorial/preparation.md @@ -29,7 +29,7 @@ Of course we also need to download and install [gir]. ```sh git submodule add https://github.com/gtk-rs/gir git config -f .gitmodules submodule.gir.update none -git submodule set-branch --branch master -- ./gir +git submodule set-branch --branch main -- ./gir cd gir cargo install --path . cd .. @@ -37,7 +37,7 @@ cd .. By adding it as a submodule, we are able to fetch future updates of the tool and we always exactly know which gir version we used to generate our bindings. We also change the setting so that the submodule is not automatically checked out, otherwise anyone using your library from git will have the useless submodule checked out. Run `git submodule update --checkout` if you want to update the submodule. -Then we set the branch of the submodule to master. +Then we set the branch of the submodule to main. If there are any updates to gir in the future, we can install them by opening our project folder `gir-tutorial` and running ```sh diff --git a/generator.py b/generator.py index 950857329..cded31df5 100755 --- a/generator.py +++ b/generator.py @@ -7,8 +7,7 @@ import asyncio DEFAULT_GIR_FILES_DIRECTORY = Path("./gir-files") -DEFAULT_GIR_DIRECTORY = Path("./gir/") -DEFAULT_GIR_PATH = DEFAULT_GIR_DIRECTORY / "target/release/gir" +DEFAULT_GIR_DIRECTORY = Path("./gir/") # TODO: This is typically the directory _of this Python script_ (which external projects symlink to) def run_command(command, folder=None): @@ -30,8 +29,13 @@ async def spawn_process(exe, args): return stdout, stderr -async def spawn_gir(gir_exe, args): - stdout, stderr = await spawn_process(gir_exe, args) +async def spawn_gir(conf, args): + if conf.gir_path: + stdout, stderr = await spawn_process(conf.gir_path, args) + else: + cargo_args = ["run", "--release", "--quiet", "--manifest-path", DEFAULT_GIR_DIRECTORY / "Cargo.toml", "--"] + stdout, stderr = await spawn_process("cargo", cargo_args + args) + # Gir doesn't print anything to stdout. If it does, this is likely out of # order with stderr, unless the printer/logging flushes in between. assert not stdout, "`gir` printed unexpected stdout: {}".format(stdout) @@ -40,10 +44,6 @@ async def spawn_gir(gir_exe, args): return "" -def update_workspace(): - return run_command(["cargo", "build", "--release"], "gir") - - def ask_yes_no_question(question, conf): question = "{} [y/N] ".format(question) if conf.yes: @@ -65,18 +65,12 @@ def update_submodule(submodule_path, conf): ): print("=> Updating submodule...") run_command(["git", "reset", "--hard", "HEAD"], submodule_path) - run_command(["git", "pull", "-f", "origin", "master"], submodule_path) + run_command(["git", "pull", "-f", "origin", "main"], submodule_path) print("<= Done!") return True return False -def build_gir(): - print("=> Building gir...") - update_workspace() - print("<= Done!") - - async def regenerate_crate_docs(conf, crate_dir, base_gir_args): doc_path = "docs.md" # Generate into docs.md instead of the default vendor.md @@ -99,7 +93,7 @@ async def regenerate_crate_docs(conf, crate_dir, base_gir_args): logs += "==> Regenerating documentation for `{}` into `{}`...\n".format( crate_dir, doc_path ) - logs += await spawn_gir(conf.gir_path, doc_args) + logs += await spawn_gir(conf, doc_args) logs += "==> Embedding documentation from `{}` into `{}`...\n".format( doc_path, crate_dir @@ -139,7 +133,7 @@ def regen_crates(path, conf): async def regenerate_crate(path, args): return "==> Regenerating `{}`...\n".format(path) + await spawn_gir( - conf.gir_path, args + conf, args ) processes.append(regenerate_crate(path, args)) @@ -194,7 +188,6 @@ def parse_args(): ) parser.add_argument( "--gir-path", - default=DEFAULT_GIR_PATH, type=file_path, help="Path of the gir executable to run", ) @@ -228,9 +221,11 @@ async def main(): if not conf.gir_files_paths: update_submodule(DEFAULT_GIR_FILES_DIRECTORY, conf) - if conf.gir_path == DEFAULT_GIR_PATH: + if conf.gir_path is None: update_submodule(DEFAULT_GIR_DIRECTORY, conf) - build_gir() + print("=> Building gir...") + run_command(["cargo", "build", "--release", "--manifest-path", DEFAULT_GIR_DIRECTORY / "Cargo.toml"]) + print("<= Done!") print("=> Regenerating crates...") for path in conf.path: diff --git a/src/analysis/bounds.rs b/src/analysis/bounds.rs index 786499518..30d1339f3 100644 --- a/src/analysis/bounds.rs +++ b/src/analysis/bounds.rs @@ -374,12 +374,12 @@ fn find_error_type(env: &Env, function: &Function) -> Option { .iter() .find(|param| param.direction.is_out() && param.is_error)?; if let Type::Record(_) = env.type_(error_param.typ) { - return Some( + Some( RustType::builder(env, error_param.typ) .direction(error_param.direction) .try_build() .into_string(), - ); + ) } else { None } diff --git a/src/analysis/ffi_type.rs b/src/analysis/ffi_type.rs index 3583ff28a..60926257a 100644 --- a/src/analysis/ffi_type.rs +++ b/src/analysis/ffi_type.rs @@ -72,7 +72,7 @@ fn ffi_inner(env: &Env, tid: TypeId, inner: &str) -> Result { Type::Basic(fund) => { use crate::library::Basic::*; let inner = match fund { - None => "libc::c_void", + None => "std::ffi::c_void", Boolean => return Ok(use_glib_if_needed(env, "ffi::gboolean").into()), Int8 => "i8", UInt8 => "u8", @@ -82,18 +82,18 @@ fn ffi_inner(env: &Env, tid: TypeId, inner: &str) -> Result { UInt32 => "u32", Int64 => "i64", UInt64 => "u64", - Char => "libc::c_char", - UChar => "libc::c_uchar", - Short => "libc::c_short", - UShort => "libc::c_ushort", - Int => "libc::c_int", - UInt => "libc::c_uint", - Long => "libc::c_long", - ULong => "libc::c_ulong", + Char => "std::ffi::c_char", + UChar => "std::ffi::c_uchar", + Short => "std::ffi::c_short", + UShort => "std::ffi::c_ushort", + Int => "std::ffi::c_int", + UInt => "std::ffi::c_uint", + Long => "std::ffi::c_long", + ULong => "std::ffi::c_ulong", Size => "libc::size_t", SSize => "libc::ssize_t", - Float => "libc::c_float", - Double => "libc::c_double", + Float => "std::ffi::c_float", + Double => "std::ffi::c_double", TimeT => "libc::time_t", OffT => "libc::off_t", DevT => "libc::dev_t", @@ -102,8 +102,8 @@ fn ffi_inner(env: &Env, tid: TypeId, inner: &str) -> Result { SockLenT => "libc::socklen_t", UidT => "libc::uid_t", UniChar => "u32", - Utf8 => "libc::c_char", - Filename => "libc::c_char", + Utf8 => "std::ffi::c_char", + Filename => "std::ffi::c_char", Type => return Ok(use_glib_if_needed(env, "ffi::GType").into()), IntPtr => "libc::intptr_t", UIntPtr => "libc::uintptr_t", diff --git a/src/analysis/rust_type.rs b/src/analysis/rust_type.rs index 142076845..400f9d9ef 100644 --- a/src/analysis/rust_type.rs +++ b/src/analysis/rust_type.rs @@ -275,6 +275,14 @@ impl<'env> RustTypeBuilder<'env> { Long => ok_and_use("libc::c_long"), // depends of target system ULong => ok_and_use("libc::c_ulong"), // depends of target system + TimeT => ok_and_use("libc::time_t"), // depends of target system + OffT => ok_and_use("libc::off_t"), // depends of target system + DevT => ok_and_use("libc::dev_t"), // depends of target system + GidT => ok_and_use("libc::gid_t"), // depends of target system + PidT => ok_and_use("libc::pid_t"), // depends of target system + SockLenT => ok_and_use("libc::socklen_t"), // depends of target system + UidT => ok_and_use("libc::uid_t"), // depends of target system + Size => ok("usize"), // depends of target system SSize => ok("isize"), // depends of target system diff --git a/src/analysis/safety_assertion_mode.rs b/src/analysis/safety_assertion_mode.rs index a6f6d259e..2fd770cb6 100644 --- a/src/analysis/safety_assertion_mode.rs +++ b/src/analysis/safety_assertion_mode.rs @@ -11,6 +11,17 @@ pub enum SafetyAssertionMode { InMainThread, } +impl std::fmt::Display for SafetyAssertionMode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + SafetyAssertionMode::None => f.write_str(""), + SafetyAssertionMode::NotInitialized => f.write_str("assert_not_initialized!();"), + SafetyAssertionMode::Skip => f.write_str("skip_assert_initialized!();"), + SafetyAssertionMode::InMainThread => f.write_str("assert_initialized_main_thread!();"), + } + } +} + impl FromStr for SafetyAssertionMode { type Err = String; fn from_str(name: &str) -> Result { diff --git a/src/analysis/signals.rs b/src/analysis/signals.rs index cb147d413..0643df79a 100644 --- a/src/analysis/signals.rs +++ b/src/analysis/signals.rs @@ -102,6 +102,7 @@ fn analyze_signal( if trampoline.is_ok() { imports.add_used_types(&used_types); imports.add("glib::prelude::*"); + imports.add("glib::object::ObjectType as _"); imports.add("glib::signal::{connect_raw, SignalHandlerId}"); imports.add("std::boxed::Box as Box_"); } diff --git a/src/analysis/types.rs b/src/analysis/types.rs index d04fe5759..1ef699c7a 100644 --- a/src/analysis/types.rs +++ b/src/analysis/types.rs @@ -77,7 +77,7 @@ impl IsIncomplete for Field { } } -impl<'a> IsIncomplete for &'a [Field] { +impl IsIncomplete for &[Field] { fn is_incomplete(&self, lib: &Library) -> bool { if self.is_empty() { return true; diff --git a/src/codegen/function.rs b/src/codegen/function.rs index 2d55b089c..f0195a68b 100644 --- a/src/codegen/function.rs +++ b/src/codegen/function.rs @@ -23,7 +23,7 @@ use crate::{ library::{self, TypeId}, nameutil::use_glib_type, version::Version, - writer::{primitives::tabs, safety_assertion_mode_to_str, ToCode}, + writer::{primitives::tabs, ToCode}, }; // We follow the rules of the `return_self_not_must_use` clippy lint: @@ -421,11 +421,7 @@ pub fn body_chunk_futures( writeln!(body)?; if !async_future.assertion.is_none() { - writeln!( - body, - "{}", - safety_assertion_mode_to_str(async_future.assertion) - )?; + writeln!(body, "{}", async_future.assertion)?; } let skip = usize::from(async_future.is_method); @@ -438,9 +434,12 @@ pub fn body_chunk_futures( let c_par = &analysis.parameters.c_parameters[par.ind_c]; let type_ = env.type_(par.typ); - let is_str = matches!(*type_, library::Type::Basic(library::Basic::Utf8)); + let is_str = matches!(type_, library::Type::Basic(library::Basic::Utf8)); + let is_slice = matches!(type_, library::Type::CArray(_)); - if *c_par.nullable { + if is_slice { + writeln!(body, "let {} = {}.to_vec();", par.name, par.name)?; + } else if *c_par.nullable { writeln!( body, "let {} = {}.map(ToOwned::to_owned);", diff --git a/src/codegen/function_body_chunk.rs b/src/codegen/function_body_chunk.rs index fa916b22c..6bee059c9 100644 --- a/src/codegen/function_body_chunk.rs +++ b/src/codegen/function_body_chunk.rs @@ -188,7 +188,7 @@ impl Builder { "Box_<({})>", calls .iter() - .map(|c| format!("&{}", c.bound_name)) + .map(|c| c.bound_name.to_string()) .collect::>() .join(", ") ); @@ -285,7 +285,7 @@ impl Builder { ) } else if calls.iter().all(|c| c.scope.is_call()) { format!( - "&({})", + "&mut ({})", calls .iter() .map(|c| format!("{}_data", c.name)) @@ -312,11 +312,15 @@ impl Builder { is_mut: false, value: Box::new(Chunk::Custom(format!( "{}{}_data", - if calls[0].scope.is_call() { "&" } else { "" }, + if calls[0].scope.is_call() { + "&mut " + } else { + "" + }, calls[0].name ))), type_: Some(Box::new(Chunk::Custom(if calls[0].scope.is_call() { - format!("&{}", calls[0].bound_name) + format!("&mut {}", calls[0].bound_name) } else { format!("Box_<{}>", calls[0].bound_name) }))), @@ -390,7 +394,7 @@ impl Builder { if full_type.is_none() { if trampoline.scope.is_call() { chunks.push(Chunk::Custom(format!( - "let {0}_data: {1} = {0};", + "let mut {0}_data: {1} = {0};", trampoline.name, trampoline.bound_name ))); } else { @@ -401,7 +405,7 @@ impl Builder { } } else if trampoline.scope.is_call() { chunks.push(Chunk::Custom(format!( - "let {0}_data: &{1} = &{0};", + "let mut {0}_data: &mut {1} = &mut {0};", trampoline.name, trampoline.bound_name ))); } else { @@ -480,7 +484,15 @@ impl Builder { ))), type_: Some(Box::new(Chunk::Custom( if !trampoline.scope.is_async() && !trampoline.scope.is_call() { - format!("&{}", full_type.1) + format!( + "&{}", + full_type + .1 + .strip_prefix("Box_<") + .unwrap() + .strip_suffix(">") + .unwrap() + ) } else { full_type.1.clone() }, @@ -512,7 +524,7 @@ impl Builder { ))); } else { body.push(Chunk::Custom(format!( - "let callback = callback{}", + "let callback = &callback{};", if let Some(pos) = pos { format!(".{pos}") } else { @@ -1005,7 +1017,7 @@ impl Builder { Chunk::FfiCallParameter { transformation_type: TransformationType::ToGlibDirect { name: if all_call { - format!("super_callback{pos} as *const _ as *mut _") + format!("super_callback{pos} as *mut _ as *mut _") } else { format!("Box_::into_raw(super_callback{pos}) as *mut _") }, diff --git a/src/codegen/object.rs b/src/codegen/object.rs index fcca7e678..39d7ff3d3 100644 --- a/src/codegen/object.rs +++ b/src/codegen/object.rs @@ -14,7 +14,7 @@ use super::{ use crate::{ analysis::{ self, bounds::BoundType, object::has_builder_properties, record_type::RecordType, - ref_mode::RefMode, rust_type::RustType, + ref_mode::RefMode, rust_type::RustType, safety_assertion_mode::SafetyAssertionMode, }, env::Env, library::{self, Nullable}, @@ -459,10 +459,15 @@ fn generate_builder(w: &mut dyn Write, env: &Env, analysis: &analysis::object::I // The split allows us to not have clippy::let_and_return lint disabled if let Some(code) = analysis.builder_postprocess.as_ref() { + // We don't generate an assertion macro for the case where you have a build post-process + // as it is only used to initialize gtk in gtk::ApplicationBuilder which is too early to assert anything writeln!(w, " let ret = self.builder.build();")?; writeln!(w, " {{\n {code}\n }}")?; writeln!(w, " ret\n }}")?; } else { + if env.config.generate_safety_asserts { + writeln!(w, "{}", SafetyAssertionMode::InMainThread)?; + } writeln!(w, " self.builder.build() }}")?; } writeln!(w, "}}") diff --git a/src/codegen/sys/cargo_toml.rs b/src/codegen/sys/cargo_toml.rs index fab07dd35..ccfccb1be 100644 --- a/src/codegen/sys/cargo_toml.rs +++ b/src/codegen/sys/cargo_toml.rs @@ -99,7 +99,9 @@ fn fill_empty(root: &mut Table, env: &Env, crate_name: &str) { fn fill_in(root: &mut Table, env: &Env) { { let package = upsert_table(root, "package"); - set_string(package, "build", "build.rs"); + package + .entry("build") + .or_insert_with(|| Value::String("build.rs".into())); // set_string(package, "version", "0.2.0"); } diff --git a/src/codegen/sys/lib_.rs b/src/codegen/sys/lib_.rs index 548f2cc62..abc97414d 100644 --- a/src/codegen/sys/lib_.rs +++ b/src/codegen/sys/lib_.rs @@ -25,18 +25,6 @@ pub fn generate(env: &Env) { save_to_file(&path, env.config.make_backup, |w| generate_lib(w, env)); } -fn write_link_attr(w: &mut dyn Write, shared_libs: &[String]) -> Result<()> { - for it in shared_libs { - writeln!( - w, - "#[link(name = \"{}\")]", - shared_lib_name_to_link_name(it) - )?; - } - - Ok(()) -} - fn generate_lib(w: &mut dyn Write, env: &Env) -> Result<()> { general::start_comments(w, &env.config)?; statics::begin(w)?; @@ -89,7 +77,6 @@ fn generate_lib(w: &mut dyn Write, env: &Env) -> Result<()> { } if !env.namespaces.main().shared_libs.is_empty() { - write_link_attr(w, &env.namespaces.main().shared_libs)?; writeln!(w, "extern \"C\" {{")?; functions::generate_enums_funcs(w, env, &enums)?; functions::generate_bitfields_funcs(w, env, &bitfields)?; @@ -223,6 +210,10 @@ fn generate_bitfields(w: &mut dyn Write, env: &Env, items: &[&Bitfield]) -> Resu .find_map(|m| m.version) .or(member.version); + if member_config.iter().any(|m| m.status.ignored()) { + continue; + } + let val: i64 = member.value.parse().unwrap(); version_condition(w, env, None, version, false, 0)?; @@ -402,6 +393,7 @@ fn generate_opaque_type(w: &mut dyn Write, name: &str) -> Result<()> { writeln!( w, r#"#[repr(C)] +#[allow(dead_code)] pub struct {name} {{ _data: [u8; 0], _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, @@ -542,6 +534,11 @@ fn generate_from_fields( generate_opaque_type(w, &fields.name)?; } else { writeln!(w, "#[repr(C)]")?; + + if fields.truncated.is_some() { + writeln!(w, "#[allow(dead_code)]")?; + } + writeln!( w, "pub {kind} {name} {{", diff --git a/src/codegen/sys/statics.rs b/src/codegen/sys/statics.rs index 94c637246..3ab802f1c 100644 --- a/src/codegen/sys/statics.rs +++ b/src/codegen/sys/statics.rs @@ -18,9 +18,10 @@ pub fn after_extern_crates(w: &mut dyn Write) -> Result<()> { let v = vec![ "", "#[allow(unused_imports)]", - "use libc::{c_int, c_char, c_uchar, c_float, c_uint, c_double,", - " c_short, c_ushort, c_long, c_ulong,", - " c_void, size_t, ssize_t, time_t, off_t, intptr_t, uintptr_t, FILE};", + "use std::ffi::{c_int, c_char, c_uchar, c_float, c_uint, c_double,", + " c_short, c_ushort, c_long, c_ulong, c_void};", + "#[allow(unused_imports)]", + "use libc::{size_t, ssize_t, time_t, off_t, intptr_t, uintptr_t, FILE};", "#[cfg(unix)]", "#[allow(unused_imports)]", "use libc::{dev_t, gid_t, pid_t, socklen_t, uid_t};", diff --git a/src/codegen/sys/tests.rs b/src/codegen/sys/tests.rs index 886f07990..04367382c 100644 --- a/src/codegen/sys/tests.rs +++ b/src/codegen/sys/tests.rs @@ -8,6 +8,7 @@ use log::info; use crate::{ analysis::types::IsIncomplete, codegen::general, + config::gobjects::GStatus, env::Env, file_saver::save_to_file, library::{self, Bitfield, Enumeration, Namespace, Type, MAIN_NAMESPACE}, @@ -28,6 +29,7 @@ struct CConstant { name: String, /// Stringified value. value: String, + status: GStatus, } pub fn generate(env: &Env, crate_name: &str) { @@ -98,14 +100,10 @@ fn prepare_ctype(env: &Env, ns: &Namespace, t: &Type) -> Option { if is_name_made_up(name) { return None; } - let cfg_condition = env - .config - .objects - .get(&full_name) - .and_then(|obj| obj.cfg_condition.clone()); + let object = env.config.objects.get(&full_name); Some(CType { name: name.to_owned(), - cfg_condition, + cfg_condition: object.and_then(|obj| obj.cfg_condition.clone()), }) } @@ -127,6 +125,7 @@ fn prepare_cconsts(env: &Env) -> Vec { Some(CConstant { name: constant.c_identifier.clone(), value: value.to_owned(), + status: GStatus::Generate, // Assume generate because we skip ignored ones above }) }) .collect(); @@ -153,6 +152,7 @@ fn prepare_cconsts(env: &Env) -> Vec { .parse::() .map(|i| (i as u32).to_string()) .unwrap_or_else(|_| member.value.clone()), + status: member.status, }); } } @@ -163,6 +163,7 @@ fn prepare_cconsts(env: &Env) -> Vec { constants.push(CConstant { name: format!("(gint) {}", member.c_identifier), value: member.value.clone(), + status: member.status, }); } } @@ -280,6 +281,9 @@ fn generate_constant_c( writeln!(w, "{}", r"int main() {")?; for cconst in cconsts { + if cconst.status.ignored() { + continue; + } writeln!(w, " PRINT_CONSTANT({name});", name = cconst.name,)?; } @@ -530,6 +534,9 @@ const RUST_LAYOUTS: &[(&str, Layout)] = &["# const RUST_CONSTANTS: &[(&str, &str)] = &["# )?; for cconst in cconsts { + if cconst.status.ignored() { + continue; + } writeln!( w, " (\"{name}\", \"{value}\"),", diff --git a/src/codegen/trait_impls.rs b/src/codegen/trait_impls.rs index 2e20a13c6..e006c4d5b 100644 --- a/src/codegen/trait_impls.rs +++ b/src/codegen/trait_impls.rs @@ -201,9 +201,16 @@ impl PartialEq for {type_name} {{ fn eq(&self, other: &Self) -> bool {{ {call} }} -}} +}}" + )?; + version_condition(w, env, None, version, false, 0)?; + cfg_condition_no_doc(w, cfg_condition, false, 0)?; -impl Eq for {type_name} {{}}" + writeln!(w)?; + writeln!( + w, + "\ + impl Eq for {type_name} {{}}" ) } @@ -231,9 +238,17 @@ impl PartialEq for {type_name} {{ fn eq(&self, other: &Self) -> bool {{ {call} == 0 }} -}} +}}" + )?; + + version_condition(w, env, None, version, false, 0)?; + cfg_condition_no_doc(w, cfg_condition, false, 0)?; -impl Eq for {type_name} {{}}" + writeln!(w)?; + writeln!( + w, + "\ + impl Eq for {type_name} {{}}" ) } @@ -261,8 +276,15 @@ impl PartialOrd for {type_name} {{ fn partial_cmp(&self, other: &Self) -> Option {{ Some(self.cmp(other)) }} -}} +}}" + )?; + version_condition(w, env, None, version, false, 0)?; + cfg_condition_no_doc(w, cfg_condition, false, 0)?; + writeln!(w)?; + writeln!( + w, + "\ impl Ord for {type_name} {{ #[inline] fn cmp(&self, other: &Self) -> std::cmp::Ordering {{ diff --git a/src/config/gobjects.rs b/src/config/gobjects.rs index b482ca7cf..a4be71c81 100644 --- a/src/config/gobjects.rs +++ b/src/config/gobjects.rs @@ -29,7 +29,7 @@ use crate::{ version::Version, }; -#[derive(Default, Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)] pub enum GStatus { Manual, Generate, diff --git a/src/config/parameter_matchable.rs b/src/config/parameter_matchable.rs index 387f64c38..510cc620f 100644 --- a/src/config/parameter_matchable.rs +++ b/src/config/parameter_matchable.rs @@ -14,7 +14,7 @@ pub trait ParameterMatchable { fn matched_parameters(&self, parameter_name: &str) -> Vec<&Self::Parameter>; } -impl<'a, U: AsRef, T: Functionlike> ParameterMatchable for [&'a T] { +impl, T: Functionlike> ParameterMatchable for [&T] { type Parameter = U; fn matched_parameters(&self, parameter_name: &str) -> Vec<&Self::Parameter> { diff --git a/src/library.rs b/src/library.rs index 69f0b5955..c14bd4395 100644 --- a/src/library.rs +++ b/src/library.rs @@ -1356,7 +1356,7 @@ impl Library { self.namespace_mut(ns_id).versions.insert(version); } - pub fn types<'a>(&'a self) -> Box + 'a> { + pub fn types<'a>(&'a self) -> Box + 'a> { Box::new(self.namespaces.iter().enumerate().flat_map(|(ns_id, ns)| { ns.types.iter().enumerate().filter_map(move |(id, type_)| { let tid = TypeId { @@ -1372,7 +1372,7 @@ impl Library { pub fn namespace_types<'a>( &'a self, ns_id: u16, - ) -> Box + 'a> { + ) -> Box + 'a> { let ns = self.namespace(ns_id); Box::new(ns.index.values().map(move |&id| { ( diff --git a/src/nameutil.rs b/src/nameutil.rs index 9a5f6076d..0529a2164 100644 --- a/src/nameutil.rs +++ b/src/nameutil.rs @@ -2,27 +2,19 @@ use std::{borrow::Cow, collections::HashMap, path::*, sync::OnceLock}; use crate::case::*; -static mut CRATE_NAME_OVERRIDES: Option> = None; +static CRATE_NAME_OVERRIDES: OnceLock> = OnceLock::new(); pub(crate) fn set_crate_name_overrides(overrides: HashMap) { - unsafe { - assert!( - CRATE_NAME_OVERRIDES.is_none(), - "Crate name overrides already set" - ); - CRATE_NAME_OVERRIDES = Some(overrides); - } + assert!( + CRATE_NAME_OVERRIDES.set(overrides).is_ok(), + "Crate name overrides already set" + ); } fn get_crate_name_override(crate_name: &str) -> Option { - unsafe { - if let Some(ref overrides) = CRATE_NAME_OVERRIDES { - if let Some(crate_name) = overrides.get(crate_name) { - return Some(crate_name.clone()); - } - } - None - } + CRATE_NAME_OVERRIDES + .get() + .and_then(|overrides| overrides.get(crate_name).cloned()) } pub fn split_namespace_name(name: &str) -> (Option<&str>, &str) { @@ -129,25 +121,6 @@ pub fn lib_name_to_toml(name: &str) -> String { name.to_string().replace(['-', '.'], "_") } -pub fn shared_lib_name_to_link_name(name: &str) -> &str { - let mut s = name; - - if s.starts_with("lib") { - s = &s[3..]; - } - - if let Some(offset) = s.rfind(".so") { - s = &s[..offset]; - } else if let Some(offset) = s.rfind(".dll") { - s = &s[..offset]; - if let Some(offset) = s.rfind('-') { - s = &s[..offset]; - } - } - - s -} - pub fn use_glib_type(env: &crate::env::Env, import: &str) -> String { format!( "{}::{}", @@ -253,14 +226,4 @@ mod tests { fn lib_name_to_toml_works() { assert_eq!(lib_name_to_toml("gstreamer-1.0"), "gstreamer_1_0"); } - - #[test] - fn shared_lib_name_to_link_name_works() { - assert_eq!(shared_lib_name_to_link_name("libgtk-4-1.dll"), "gtk-4"); - assert_eq!(shared_lib_name_to_link_name("libatk-1.0.so.0"), "atk-1.0"); - assert_eq!( - shared_lib_name_to_link_name("libgdk_pixbuf-2.0.so.0"), - "gdk_pixbuf-2.0" - ); - } } diff --git a/src/parser.rs b/src/parser.rs index 655f485b6..c1c38b4d6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -139,7 +139,9 @@ impl Library { "function" => self.read_global_function(parser, ns_id, elem), "constant" => self.read_constant(parser, ns_id, elem), "alias" => self.read_alias(parser, ns_id, elem), - "boxed" | "function-macro" | "docsection" => parser.ignore_element(), + "boxed" | "function-macro" | "docsection" | "function-inline" => { + parser.ignore_element() + } _ => { warn!("<{} name={:?}>", elem.name(), elem.attr("name")); parser.ignore_element() @@ -386,6 +388,7 @@ impl Library { "doc-deprecated" => parser.text().map(|t| doc_deprecated = Some(t)), "source-position" => parser.ignore_element(), "attribute" => parser.ignore_element(), + "method-inline" => parser.ignore_element(), _ => Err(parser.unexpected_element(elem)), })?; diff --git a/src/writer/mod.rs b/src/writer/mod.rs index 09a4ee796..ac46171a4 100644 --- a/src/writer/mod.rs +++ b/src/writer/mod.rs @@ -4,13 +4,3 @@ pub mod to_code; // TODO:remove pub pub mod untabber; pub use self::{defines::TAB, to_code::ToCode}; -use crate::analysis::safety_assertion_mode::SafetyAssertionMode; - -pub fn safety_assertion_mode_to_str(s: SafetyAssertionMode) -> &'static str { - match s { - SafetyAssertionMode::None => "", - SafetyAssertionMode::NotInitialized => "assert_not_initialized!();", - SafetyAssertionMode::Skip => "skip_assert_initialized!();", - SafetyAssertionMode::InMainThread => "assert_initialized_main_thread!();", - } -} diff --git a/src/writer/to_code.rs b/src/writer/to_code.rs index 69256fb6f..038813f20 100644 --- a/src/writer/to_code.rs +++ b/src/writer/to_code.rs @@ -1,6 +1,6 @@ use std::fmt::Write; -use super::{primitives::*, safety_assertion_mode_to_str}; +use super::primitives::*; use crate::{ chunk::{Chunk, Param, TupleMode}, codegen::{translate_from_glib::TranslateFromGlib, translate_to_glib::TranslateToGlib}, @@ -137,7 +137,7 @@ impl ToCode for Chunk { lines.push(s); lines } - AssertInit(x) => vec![safety_assertion_mode_to_str(x).to_owned()], + AssertInit(x) => vec![x.to_string()], Connect { ref signal, ref trampoline, diff --git a/src/xmlparser.rs b/src/xmlparser.rs index 911c47cf4..56e334b0b 100644 --- a/src/xmlparser.rs +++ b/src/xmlparser.rs @@ -142,7 +142,7 @@ impl Element { } } -impl<'a> XmlParser<'a> { +impl XmlParser<'_> { pub fn from_path(path: &Path) -> Result, String> { match File::open(path) { Err(e) => Err(format!("Can't open file \"{}\": {}", path.display(), e)),