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

Remove platform-specific conditional dependencies #111

Merged

Conversation

dominic-mulligan-arm
Copy link
Member

@dominic-mulligan-arm dominic-mulligan-arm commented Mar 22, 2021

Remove platform-specific conditional dependencies of the form

[target.'cfg(target_arch = "X")'.dependencies]

from various Cargo.toml files. With the move to support AArch64 and X64 Linux processes as a backend these are no longer appropriate. Instead, adopted optional dependencies selected by feature flags to select backend-specific dependencies.

@dominic-mulligan-arm dominic-mulligan-arm added build-process Something related to the Veracruz build process always-refactoring A refactoring/code quality change to the Veracruz codebase labels Mar 22, 2021
@dominic-mulligan-arm dominic-mulligan-arm added this to the Veracruz as a Linux process milestone Mar 22, 2021
geky
geky previously approved these changes Mar 22, 2021
Copy link
Member

@geky geky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me 👍

@veracruz-project-owner
Copy link
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: Veracruz
  • Commit ID: b5e625c
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@geky
Copy link
Member

geky commented Mar 23, 2021

I don't think there's a reason to not merge this, but have you considered instead making these use cfg(feature = sgx), etc, directly tying them to the feature flags?

After #81, they may end up not even needing to be conditional.

@dominic-mulligan-arm
Copy link
Member Author

I don't think there's a reason to not merge this, but have you considered instead making these use cfg(feature = sgx), etc, directly tying them to the feature flags?

After #81, they may end up not even needing to be conditional.

I was under the impression that does not work in Cargo, see e.g. 1. I'll experiment, though, and use that approach if I can indeed get it to work.

gbryant-arm
gbryant-arm previously approved these changes Mar 23, 2021
@veracruz-project-owner
Copy link
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: Veracruz
  • Commit ID: 56d95a9
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@dominic-mulligan-arm
Copy link
Member Author

@geky, selecting target dependencies based on a feature definitely does not work in Cargo. Trying it, you get an explicit warning:

warning: Found feature = ... in target.'cfg(...)'.dependencies. This key is not supported for selecting dependencies and will not work as expected. Use the [features] section instead: https://doc.rust-lang.org/cargo/reference/features.html

Moreover, I think this change is going to be much more involved than I first appreciated. The target_arch, target_env, and target_os are derived from the target triple used for compilation. At the moment, we are compiling for TrustZone with a standard aarch64-unknown-linux-gnu target triple, which does not allow us to distinguish whether we are compiling for TrustZone or plain Linux by examining target_os (which is Linux, in this case). Similarly, we have an analogous issue when compiling for SGX, too.

To properly fix this, we need to follow the approach used in the SDK at the moment, and introduce an OPTEE and SGX-specific target triple, to allow us to distinguish between the different targets (actually, both the Rust OPTEE and SGX SDKs already provide their own triple JSON specification files for this purpose). Unfortunately, I think that this means we will need to use Xargo, instead of Cargo, for compiling the project!

@dominic-mulligan-arm
Copy link
Member Author

dominic-mulligan-arm commented Mar 23, 2021

Thinking more, an alternative would be to drop target-based conditional dependencies altogether, and just use features to select dependencies. Given #81 I think this would actually be the neatest: all platform-specific dependencies are imported by platform-specific crates, which are then selected by other platform-neutral crates using features (in hindsight, this may be what @geky was talking about, above, which I missed).

@dreemkiller
Copy link
Member

Does anyone remember why we (mostly I...) didn't use xargo to begin with for the TA code?
The example code in the SDK uses Xargo, so I don't recall why we didn't.

@dominic-mulligan-arm
Copy link
Member Author

Does anyone remember why we (mostly I...) didn't use xargo to begin with for the TA code?
The example code in the SDK uses Xargo, so I don't recall why we didn't.

Well... having used Xargo in the SDK it's quite fickle, no longer maintained, and very poorly documented. I think not using it, if it wasn't needed at the time, was a pretty defensible decision to make. I think at one point about a year ago I tried adopting Xargo as our main build tool and gave up. I may be more successful this time in using it, with the experience from deploying it in the SDK, but I think we made the right decision in avoiding it early in the project.

@ShaleXIONG
Copy link
Member

ShaleXIONG commented Mar 23, 2021

Thinking more, an alternative would be to drop target-based conditional dependencies altogether, and just use features to select dependencies. Given #81 I think this would actually be the neatest: all platform-specific dependencies are imported by platform-specific crates, which are then selected by other platform-neutral crates using features (in hindsight, this may be what @geky was talking about, above, which I missed).

All those packages actually are already guarded by features. I marked many packages as optional and will only been imported when certain features are selected. It will be double assurance by also using (legacy) target-based conditions. However, I do not mind to drop target-based conditions all together.

For @dreemkiller question: when I updated sgx-sdk, I have spent some time on swaping all to xargo. I vaguely remember the interactions between xargo importing tz backend and xargo importing sgx backend causes some problems and then I gave up at some point.

@dominic-mulligan-arm
Copy link
Member Author

Thinking more, an alternative would be to drop target-based conditional dependencies altogether, and just use features to select dependencies. Given #81 I think this would actually be the neatest: all platform-specific dependencies are imported by platform-specific crates, which are then selected by other platform-neutral crates using features (in hindsight, this may be what @geky was talking about, above, which I missed).

All those packages actually are already guarded by features. I marked many packages as optional and will only been imported when certain features are selected. It will be double assurance by also using (legacy) target-based conditions. However, I do not mind to drop target-based conditions all together.

For @dreemkiller question: when I updated sgx-sdk, I have spent some time on swaping all to xargo. I vaguely remember the interactions between xargo importing tz backend and xargo importing sgx backend causes some problems and then I gave up at some point.

Thinking more, an alternative would be to drop target-based conditional dependencies altogether, and just use features to select dependencies. Given #81 I think this would actually be the neatest: all platform-specific dependencies are imported by platform-specific crates, which are then selected by other platform-neutral crates using features (in hindsight, this may be what @geky was talking about, above, which I missed).

All those packages actually are already guarded by features. I marked many packages as optional and will only been imported when certain features are selected. It will be double assurance by also using (legacy) target-based conditions. However, I do not mind to drop target-based conditions all together.

For @dreemkiller question: when I updated sgx-sdk, I have spent some time on swaping all to xargo. I vaguely remember the interactions between xargo importing tz backend and xargo importing sgx backend causes some problems and then I gave up at some point.

Does anybody know why some dependencies are guarded by target-dependent conditional clauses in Cargo.toml files, then?

@dreemkiller
Copy link
Member

Does anybody know why some dependencies are guarded by target-dependent conditional clauses in Cargo.toml files, then?

That's likely legacy cruft. We initially did not use features, instead relying on target information. The features were added later, and the target checks were probably just not removed.

@dominic-mulligan-arm
Copy link
Member Author

OK, that's what I was hoping. Then the best way forward seems to be clear: get rid of the target-conditional dependencies and use (optional) features for everything, instead. No need for Xargo, and this will fit nicely with #81.

... over use of target_arch, as with Nitro and upcoming Linux support this is now ambiguous.
@veracruz-project-owner
Copy link
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: Veracruz
  • Commit ID: 603edfe
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

…go.toml files

Removed [target.'cfg(target_env = "XXX")'.dependencies], and similar, from Cargo.toml files in favour of optional dependencies selected by Cargo features.
@veracruz-project-owner
Copy link
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: Veracruz
  • Commit ID: 71adfaf
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@veracruz-project-owner
Copy link
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: Veracruz
  • Commit ID: 0482a21
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@dominic-mulligan-arm dominic-mulligan-arm changed the title Prefer target_env and target_os for conditional compilation Remove platform-specific conditional dependencies Mar 25, 2021
…rom build.rs files

Used features instead of querying of the target-triple in build.rs files for runtime-manager and veracruz-server.

Removed superfluous dev-dependency from Cargo.toml file for runtime-manager and veracruz-server.
@veracruz-project-owner
Copy link
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: Veracruz
  • Commit ID: d814e06
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@dominic-mulligan-arm
Copy link
Member Author

+1 reached, merging

@dominic-mulligan-arm dominic-mulligan-arm merged commit 2bd045b into veracruz-project:main Mar 25, 2021
@dominic-mulligan-arm dominic-mulligan-arm deleted the target-env branch March 25, 2021 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
always-refactoring A refactoring/code quality change to the Veracruz codebase build-process Something related to the Veracruz build process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants