Skip to content
New issue

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

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

Already on GitHub? # to your account

Trunk builds an arbitrary binary out of available ones when not explicitly selected in index.html #475

Closed
samoylovfp opened this issue Jan 3, 2023 · 9 comments
Labels

Comments

@samoylovfp
Copy link
Contributor

Example

This project defines two different binaries
https://gitlab.com/samoylovfp/rust-browser-extension/-/tree/15d24e062e68cd637bc9ce39e1fefd0fedcbd89c
when running trunk build it takes an arbitrary one of those and processes it into the dist directory.

Running trunk build repeatedly flips between two different outcomes

$ for i in `seq 10`; do trunk build &>/dev/null; ls dist/*.wasm; done
dist/ff-ext-793a8876bb5256ae_bg.wasm
dist/ff-ext-a98d0f18bde50465_bg.wasm
dist/ff-ext-793a8876bb5256ae_bg.wasm
dist/ff-ext-793a8876bb5256ae_bg.wasm
dist/ff-ext-793a8876bb5256ae_bg.wasm
dist/ff-ext-793a8876bb5256ae_bg.wasm
dist/ff-ext-793a8876bb5256ae_bg.wasm
dist/ff-ext-793a8876bb5256ae_bg.wasm
dist/ff-ext-a98d0f18bde50465_bg.wasm
dist/ff-ext-793a8876bb5256ae_bg.wasm

Expected

One of the following to happen

  • trunk to pick up binary that has the same name as the package
  • trunk to emit an error since there is an ambiguity in what to build with an explanation on how to add a <link data-trunk ... /> tag into index.html to resolve the ambiguity and exit with a non-zero code.

Thanks for the awesome tool!
It is extremely handy to have a single command to build a deployable dist with a single command with no npm dependencies!

@samoylovfp
Copy link
Contributor Author

I am willing to provide an implementation if the course of action is OK with maintainers

@thedodd
Copy link
Member

thedodd commented Jan 3, 2023

Hello there. There is indeed rather strange behavior; however, I am not so sure that this is an issue with Trunk. Technically, Trunk simply uses Cargo to perform the builds, and will interpolate details into the call to cargo based on the details (or lack thereof) in the <link data-trunk rel="rust"/>.

As stated in the docs here: data-bin: (optional) the name of the binary to compile and load. If the Cargo project has multiple binaries, this value will be required for proper functionality. So, this is apparently some ambiguity with Cargo (as that is what is used to build any Rust code), and in order to address this, you should use the data-bin attribute in your rel="rust" link in order to address this issue.

Hopefully that helps :). If so, I'll let you close this issue.

@thedodd
Copy link
Member

thedodd commented Jan 3, 2023

Additionally, we could detect such cases proactively, and then bail with a warning to ensure that folks don't run into this type of issue.

@samoylovfp
Copy link
Contributor Author

I'll see how difficult it is to add this check

samoylovfp added a commit to samoylovfp/trunk that referenced this issue Jan 4, 2023
proceeding leads to indeterminte result
where trunk picks up an arbitrary binary for the target.
See trunk-rs#475
samoylovfp added a commit to samoylovfp/trunk that referenced this issue Jan 4, 2023
proceeding leads to indeterminte result
where trunk picks up an arbitrary binary for the target.
See trunk-rs#475
@samoylovfp
Copy link
Contributor Author

Please see related PR
#476

samoylovfp added a commit to samoylovfp/trunk that referenced this issue Jan 4, 2023
proceeding leads to indeterminte result
where trunk picks up an arbitrary binary for the target.
See trunk-rs#475
samoylovfp added a commit to samoylovfp/trunk that referenced this issue Jan 5, 2023
proceeding leads to indeterminte result
where trunk picks up an arbitrary binary for the target.
See trunk-rs#475
samoylovfp added a commit to samoylovfp/trunk that referenced this issue Mar 26, 2023
proceeding leads to indeterminte result
where trunk picks up an arbitrary binary for the target.
See trunk-rs#475
samoylovfp added a commit to samoylovfp/trunk that referenced this issue Apr 1, 2023
proceeding leads to indeterminte result
where trunk picks up an arbitrary binary for the target.
See trunk-rs#475
samoylovfp added a commit to samoylovfp/trunk that referenced this issue Apr 3, 2023
proceeding leads to indeterminte result
where trunk picks up an arbitrary binary for the target.
See trunk-rs#475
thedodd pushed a commit that referenced this issue Apr 24, 2023
* Gather all artifacts from cargo cmd output
* Abort build if binary artifact ambiguous

proceeding leads to indeterminte result
where trunk picks up an arbitrary binary for the target.
See #475
@Ddystopia
Copy link

Is code from your PR installed with cargo install trunk? Because I still have that issue.

@samoylovfp
Copy link
Contributor Author

According to the changelog this fix is not yet released.

As a workaround you can cargo install trunk --git https://github.com/thedodd/trunk

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Sep 11, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 17, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants