Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build without proc macros #1226

Merged
merged 40 commits into from
Mar 13, 2021
Merged

Conversation

chippers
Copy link
Member

@chippers chippers commented Feb 13, 2021

Warning: This code is incomplete and partially broken. Currently it can run examples (not sure if correctly yet), but tests are completely broken.

This ticket, like #850, is going to be a scratchpad; this time for changing the build code to not rely on proc-macros and to try and implement the ability to create an AsTauriContext both automatically and manually.

Changed so far:

  • Deleted tauri-macros.
    • The ideal goal is to have no proc-macros, so it will start off with none. It may be necessary to split the load between proc-macros and codegen like many other crates (e.g. phf).
  • New build.rs based builder in tauri::build (incomplete api).
    • Allows generating an AsTauriContext scoped struct that can be passed to AppBuilder so far.
  • Examples are moved from tauri/examples/ to examples/ and added to the workspace.
    • Because build.rs is not run in library crates for binaries, it was impossible to have an [[example]] that was able to use code meant for build.rs at build time. Workspace examples still check type correctness during cargo clippy.

Some notes:

Because a build script cannot be run for cargo test of a library without a completely custom harness, the tests are currently completely broken. The following resolutions will be tried in order:

  1. Change AsTauriContext to require Send + Sync to allow it to be built as a &'static Config during build.rs and around a manually implemented struct such as struct MyContext(Arc<RwLock<MyData>>); to allow building a context during runtime before AppBuilder::build.
    Benefits: Allows the user to have completely custom context behavior if they wish which might enable some advanced use-cases while still having a simple automatically implemented context available with a build.rs. It also allows for us to build a context during a test setup without relying on a build script (hard for tests in a lib).

  2. Implement a function based macro to completely replace the current FromTauriContext derive proc-macro. This macro would have shared architecture with the codegen implementation, and allow the user to decide between using a build.rs and a proc-macro. A proc-macro would enable building an AsTauriContext impl during tests and other cases where having a build script is infeasible.

⚠️ This change will mess up if you keep tauri-apps/examples in this repo's root examples/ crate like that repo expects. Watch out.

This change is probably overkill, it's a stopgap while i determine the
minimum necessary changes to examples to make them useful to the workspace.
I can't tell if they are actually working, and if my changes so far broke it.

In this commit tests are also not working, only `cargo clippy` is. be warned.
@chippers
Copy link
Member Author

chippers commented Feb 13, 2021

A benefit of the build feature in tauri-utils is the new tauri-utils::config::build submodule that utilizes quote::ToTokens to spit out a literal Config instance. This allows us to only parse the config once while building the Context (at build time right now) and to avoid parsing it again in AppBuilder like it currently does.

Here's the $OUT_DIR/tauri-context.rs auto-generated code that is built when building communications so far https://gist.github.com/chippers/f19b5365ff0163f66e2066c0c3b28f41 (formatted and removed the instance of AutoTauriContext{} at the end since it's used as an expression in an include!)

the ToTokens impl code is a bit tedious right now, but simple and effective

chippers and others added 7 commits February 20, 2021 19:57
This is to allow typechecking examples while developing while still
allowing the examples to be run as part of the workspace and standalone.

The api example is broken for now and will be removed shortly. It can be
added again when the dist files are added to git so that extra build
steps are not needed before running `cargo run --bin api`.
@chippers
Copy link
Member Author

as noted in the 32271b2 commit message, e1ce72e is a temporary measure to prevent extra build steps before cargo run --bin api. e1ce72e should be reverted after build files are added to git

@chippers chippers mentioned this pull request Feb 28, 2021
12 tasks
This includes some changes to allow both to work
like usual, tests are not done yet, and this contains some highly experimental
changes in order to see what is possible during build time for tauri
@chippers
Copy link
Member Author

chippers commented Mar 2, 2021

okay so this last commit d230b04 was pretty large, with some very extreme, significant changes. It's late so ill probably discuss some decisions made during that commit more later on.

here's a mess of bullet points before i forget:

  • I haven't even touched tests, expect things to be broken until i add the next bullet point
  • FromTauriContext completely removed with no current replacement. this will be replaced with a function proc-macro that utilizes the tauri-codegen crate to generate the code
  • tauri-build now exists and has a tauri-build::build() function that should be a cross-platform alternative handling things like Window Resource files. now, the applications build.rs can be as short as fn main() { tauri_build::build(); }
  • tauri-build has a CodegenContext builder for generating an AsTauriContext during build time. only way to generate for now until I add that aforementioned function proc-macro. this functionality is locked behind the codegen feature on the tauri-build crate.
  • we no longer need OUT_DIR while generating code, which means that the proc-macro will no longer error if there is no build script for the application project. This was possible by injecting the compressed gzip bytes into the generated code instead of writing it to a file and using include_bytes!. This may have a more adverse effect for large files, but I couldn't really tell the difference between embedded directly and using include_bytes! if there is any. I would like to discuss moving to brotli (BSD-3-clause) crate for compression and decompression for embedded assets, as it can save typically another 10-20% in bytes, which could be significant for compile times (speculation) and faster to decompress during runtime
  • api example is still temporarily disabled
  • AppBuilder::build return has changed from tauri::Result<App> to App which eliminates the need to .unwrap()/handle errors before App::run
  • struct Assets -> EmbeddedAssets and now there is a trait Assets meant to represent retrievable assets. this will be important later when i try to allow runtime, non-'static assets to be used in a AsTauriContext.

@ me on discord if you read through it and have questions

@chippers
Copy link
Member Author

chippers commented Mar 7, 2021

added tauri::generate_tauri_context!() to replace the old FromTauriContext. With this addition, the helloworld works fine using the macro, and cargo test works again with the tests using the new macro. yarn test also works from cli/tauri.js.

I've added back the api example, stripped down like the others, but I ran into console errors about ReferenceError: Can't find variable: cli from bundle.js. I don't have time to look into it right now, and everything else is ready. take a look at it before you merge if you want. The rust code builds fine

With the exception of the API example, this merge is ready as in "it works, and all previous tests pass again", but not release ready. I plan to refine the newly exposed crates, APIs, and codegen error messages in future pull requests before release

I'll be a bit busy today, but @ me on discord for any questions, but this should be merge ready keeping the previous information in mind

@chippers chippers marked this pull request as ready for review March 7, 2021 21:14
@chippers chippers requested a review from a team as a code owner March 7, 2021 21:14
@chippers chippers requested a review from a team March 7, 2021 21:14
@chippers chippers requested review from a team March 7, 2021 21:14
@chippers
Copy link
Member Author

chippers commented Mar 8, 2021

The checks should all pass now, and the api example is building and running again

@lucasfernog lucasfernog changed the title wip: build without proc macros feat: build without proc macros Mar 12, 2021
@lucasfernog lucasfernog merged commit c88838a into dev Mar 13, 2021
@lucasfernog lucasfernog deleted the feat/build-without-proc-macros branch March 13, 2021 01:10
jbolda added a commit that referenced this pull request Apr 11, 2021
* chore(deps) Update Tauri JS CLI (#1319)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri Core (#1318)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri API (#1316)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate serde_json to 1.0.64 (#1315)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate once_cell to 1.7.2 (#1314)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate image to 0.23.14 (#1313)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* feat(cli/build): improve no distDir error message (#1306)

* feat(cli/build): improve no distDir error message

* chore: use Path's Display impl

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* chore(deps) Update Tauri API Definitions (#1317)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* feat(bundler/wix): install webview2 runtime (#1329)

* feat(bundler/wix): install webview2 runtime

* add changefile

* chore(deps) Update Tauri API Definitions (major) (#1290)

* chore(deps) Update Tauri API Definitions

* chore: update to husky v5

* chore: remove husky script

* chore: recreate lock file

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* chore(deps) Update Tauri JS CLI (#1291)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* refactor(core): app hooks (#1332)

* fix(api/window): rename manager export to appWindow (#1342)

* feat(api/shell): allow open command to open files (#1341)

* chore(deps) Update Tauri API Definitions (#1344)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate tokio to 1.3 (#1343)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate open to 1.6.0 (#1348)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(core): wrong usage of wry RPC on event API (#1351)

* copy cli config definition window visibility defaults (#1353)

* feat(core): add file drop handler (#1352)

* fix: get correct resource dir in AppImge (fix #1308) (#1333)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* feat: build without proc macros (#1226)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* chore(deps) Update Tauri JS CLI (#1346)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* refactor(core): use Mutex in std to reduce async usage (#1350)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* fix(examples): build error (#1354)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* API example new ui (#1310)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* chore(deps): remove `winres` from template (#1357)

* refactor(core): add `unlisten`, `once` APIs to the event system (#1359)

* fix(cli): use correct arg in `_blanks` links polyfill (#1362)

* fix(api/http): correct types (#1360)

* fix(api/http): correct types

* Add changes

* Update correct-http-api-types.md

* chore(deps) Update Tauri JS CLI (#1364)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri API Definitions (#1363)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(tauri/webview): Use different user_data_path for Windows (#1365) (#1366)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* fix(config): serde_json::Value::Object takes a Map instead of HashMap (#1371)

* fix(config): serde_json::Value::Object takes a Map instead of HashMap

* fix: fmt

* fix(tauri.js): init command properly building with manifests (#1374)

* fix(tauri.js): init command properly building with manifests

* fix: tests

* feat(bundler): add visual c++ redistributable files with MSM (#1368)

* refactor(core): reduce usage on arc and mutex (#1361)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* feat(config): allow setting product name and version on tauri.conf.json (#1358)

* feat: add current working directory to path api module (#1375)

* refactor(core): move bundle script to /tauri crate (#1377)

* refactor(core): move bundle script to /tauri crate

* fix(cli): clippy

* fix(core): tests

* refactor(core): custom protocol URL uses the app identifier (#1376)

* refactor(core): custom protocol URL uses the app identifier

* fix: clippy

* fix(tauri-api): remove .exe from app_name on windows (#1379)

* chore(deps) Update Tauri API Definitions (#1384)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate tokio to 1.4 (#1383)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(cli): prmpt user before install deps in init (#1381)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* chore(deps) Update dependency rollup to v2.42.4 (#1386)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* refactor(cli): rewrite init command in Rust (#1382)

Co-authored-by: nothingismagick <denjell@mailscript.com>

* refactor(bundler): specific settings on dedicated structs, update README (#1380)

* replace lazy_static uses with once_cell (#1391)

* chore(deps) Update Tauri JS CLI (#1385)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* refactor(cli): rewrite info in Rust (#1389)

* refactor(core): remove async from app hooks, add InvokeMessage type (#1392)

* fix(cli): disable custom-protocol feature on dev command (#1393)

* Fix extremely slow dev builds caused by embedding + compressing assets at compile time (#1395)

* feat(bundler) code signing (#473)

Co-authored-by: Rajiv Shah <rajivshah1@icloud.com>
Co-authored-by: David Lemarier <david@lemarier.ca>

* feat(cli): run beforeDev and beforeBuild in a shell, closes #1295 (#1399)

* update to sharp 0.28.0 for cpu arm (m1) (#1404)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* feat(cli): propagate args passed after `dev --`, closes #1406 (#1407)

* refactor(api): use secure RNG, closes #1356 (#1398)

* chore(deps) Update Tauri API Definitions (#1411)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate rfd to 0.2.2 (#1410)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri CLI (#1413)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri Bundler (#1412)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* refactor(core): rewrite shell execute API, closes #1229 (#1408)

* chore(deps) Update dependency @rollup/plugin-commonjs to v18 (#1415)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri JS CLI (#1414)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix: asset resolution on debug mode

* fix(core): ignore query string on custom protocol asset resolver (#1420)

* wire up existing and adjust recipe configuration

* merge dev

* fix default app name

* clean up vanillajs and proper pass args

* use scaffe to copy the react templates

* fix(api): remove cjs, rename .mjs to .js

* chore: tauri.js dead code elim (#1422)

* remove templates, only used it CTA

* help command is empty, remove

* delete files that aren't imported / required

* set files array to ignore src and config files

* remove unused deps

* add arch notes for future ref

* change file

* allow specifying a binary

* resolve last bits to reach scaffe

* adjust vanilla js template dir path

Co-authored-by: Sanket Chaudhari <chaudharisanket2000@gmail.com>

* fix up cra scaffolding

* remove none and rely on vanillajs

* log shell commands

* remove no recipe question branch

* shift react template for better overwrite copying

* update deps

* simple readme

* implement dep manager

* pretty

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Noah Klayman <noahklayman@gmail.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Co-authored-by: Lucas Fernandes Nogueira <lucasfernandesnog@gmail.com>
Co-authored-by: chip <chip@chip.sh>
Co-authored-by: Gabe Cohen <gcc3.14@gmail.com>
Co-authored-by: Ngo Iok Ui (Wu Yu Wei) <wusyong9104@gmail.com>
Co-authored-by: Alve Larsson <larsalvelarsson@gmail.com>
Co-authored-by: Amr Bashir <48618675+amrbashir@users.noreply.github.com>
Co-authored-by: Kid <44045911+kidonng@users.noreply.github.com>
Co-authored-by: david <david@lemarier.ca>
Co-authored-by: nothingismagick <denjell@mailscript.com>
Co-authored-by: William <william@venner.io>
Co-authored-by: Rajiv Shah <rajivshah1@icloud.com>
Co-authored-by: Mehdi Rezaei <mehdiraized@gmail.com>
Co-authored-by: Sanket Chaudhari <chaudharisanket2000@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants