-
Notifications
You must be signed in to change notification settings - Fork 42
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
Guidance for build dependencies #73
Comments
Your approach to have crates pass features along to sub crates is what I've been doing in my own multi-crate projects. I don't know of a better way at the moment. One idea comes to mind - can you use cargo tree and confirm that you just have a single version of the profiling and profiling-procmacro crates? I'm wondering if it's possible that the feature is enabled for version 1.0.x but not for 1.0.y. Another workaround would be to have a hacked version of the profiling crate that hardcodes a particular backend as always on and then use cargo's crate patching functionality to force using your locally modified version of the profiling crates. This avoids any reliance on features to accomplish the task at hand. It's ugly and I don't love it, but I bet it would work. Although this still means you're profiling all crates, not just a specific crate. |
Yes - in the actual case of I've found a solution I'm happy with (see the commits on this branch of the sample repository). This keeps the documented public API of This allows you to profile only the crate you're interested in, example - cargo tree -e features --features profile-with-puffin
my-bin v0.1.0 (/profiling-test/my-bin)
├── bar-lib feature "default"
│ └── bar-lib v0.1.0 (/profiling-test/bar-lib)
│ └── profiling feature "default"
│ ├── profiling v0.1.0 (/profiling-test/profiling)
│ │ ├── profiling-procmacros feature "default"
│ │ │ └── profiling-procmacros v0.1.0 (proc-macro) (/profiling-test/profiling-procmacros)
│ │ │ ├── quote v1.0.35
│ │ │ └── syn feature "full"
│ │ │ └── syn v2.0.55 (*)
│ │ └── puffin feature "default"
│ │ └── [...REMOVED FOR CLARITY...]
│ └── profiling feature "procmacros"
│ ├── profiling v0.1.0 (/profiling-test/profiling) (*)
│ └── profiling feature "profiling-procmacros"
│ └── profiling v0.1.0 (/profiling-test/profiling) (*)
└── foo-lib feature "default"
└── foo-lib v0.1.0 (/profiling-test/foo-lib)
[build-dependencies]
└── child-lib feature "default"
└── child-lib v0.1.0 (/profiling-test/child-lib)
└── profiling feature "default"
├── profiling v0.1.0 (/profiling-test/profiling)
│ └── profiling-procmacros feature "default" (*)
└── profiling feature "procmacros"
├── profiling v0.1.0 (/profiling-test/profiling) (*)
└── profiling feature "profiling-procmacros"
└── profiling v0.1.0 (/profiling-test/profiling) (*) In the above example |
I synced the project and found a pretty straightforward solution. Add this to any of the crates you control, such as my-bin:
And enable the profile-with-puffin feature on it. You can have profiling listed as both a dependency and a build-dependency simultaneously. This appears to propagate the feature as needed. Does this work for you? |
Yes that works perfectly and fixes my issue with This is better than either fix I suggested and seems like a good item to document for cases where build dependencies use |
When
[build-dependencies]
useprofiling
it can cause trouble building the target crate. If possible I'm looking for advice and updates that could be made to the documentation.Background
Recently the
image
crate was updated to include a dependency onrav1e
(viaravif
). This dependency usesprofiling
in the normal way, but fails whenimage
is used from build script of a profiling build. This is somewhat complex so I made a simple repro case.Sample repository
Problem repo
https://github.com/attackgoat/profiling-test/tree/main
my-bin
includesfoo-lib
which useschild-lib
in a build scriptchild_lib
usesprofiling
my-bin
includesbar-lib
which usesprofiling
How to reproduce the issue
The second
run
generates:How to fix:
attackgoat/profiling-test@main...attackgoat:fix
Proposed fix
If I understand what is happening here correctly, the procmacro crate is configured to use
puffin
, but theprofiling
crate used by the build is not similarly configured. It's unclear to me if this is a Cargo bug or it is intended that procedural macros are only built once and not separately for the build dependencies.The fix I used in the sample repository is to expose
profile-with-*
features in any crate whose dependencies expose such features, and enable them in a pass-through manner.foo-lib
does not use profiling but provides the features so thatmy-bin
can enable profiling inchild-lib
.This works, in that I can now use the
image
crate in build scripts and also useprofiling
on the resulting binary, but the downside is that I'll have to go ask authors of these "middle" crates to expose and maintain these features in their creates too. I also cannot make a build which does not profilerav1e
but does profile the code I'm interested in.Is there a better way to do this?
The text was updated successfully, but these errors were encountered: