-
Notifications
You must be signed in to change notification settings - Fork 129
Resolve duplicate crate dependencies (support multiple versions) #430
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| [package] | ||
| name = "dependency3" | ||
| version = "0.1.0" | ||
| edition = "2018" | ||
|
|
||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
|
||
| [dependencies] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| pub struct Foo { | ||
| x: i32, | ||
| } | ||
|
|
||
| // Export a function that takes a struct type which differs between this crate | ||
| // and the other vesion | ||
| pub fn take_foo(foo: &Foo) -> i32 { | ||
| foo.x | ||
| } | ||
|
|
||
| pub fn give_foo() -> Foo { | ||
| Foo { x: 1 } | ||
| } | ||
|
|
||
| pub fn get_int() -> i32 { | ||
| // Use a constant to force an MIR GlobalAllocation::Memory. | ||
| // Use a non-i32 so there will be a conflict between this | ||
| // version and the other version. The constant is also a | ||
| // different value than the other version of this dependency. | ||
| let one = &(1 as i8); | ||
avanhatt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return *one as i32 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| [workspace] | ||
| members = ["main", "dependency1", "dependency2", "dependency3"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| [package] | ||
| name = "dependency1" | ||
| version = "0.1.0" | ||
| edition = "2018" | ||
|
|
||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
|
||
| [dependencies] | ||
| dependency3 = { path = "../dependency3" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| use dependency3; | ||
|
|
||
| pub fn delegate_get_int() -> i32 { | ||
| dependency3::get_int() | ||
| } | ||
|
|
||
| pub fn delegate_use_struct() -> i32 { | ||
| let foo = dependency3::give_foo(); | ||
| dependency3::take_foo(&foo) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| [package] | ||
| name = "dependency2" | ||
| version = "0.1.0" | ||
| edition = "2018" | ||
|
|
||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
|
||
| [dependencies] | ||
| dependency3 = { path = "../../dependency3" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| use dependency3; | ||
|
|
||
| pub fn delegate_get_int() -> i32 { | ||
| dependency3::get_int() | ||
| } | ||
|
|
||
| pub fn delegate_use_struct() -> i32 { | ||
| let foo = dependency3::give_foo(); | ||
| dependency3::take_foo(&foo) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| [package] | ||
| name = "dependency3" | ||
| version = "0.1.1" | ||
| edition = "2018" | ||
|
|
||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
|
||
| [dependencies] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| pub struct Foo { | ||
| x: i32, | ||
| // This field only in this version. | ||
| y: i32, | ||
| } | ||
|
|
||
| // Export a function that takes a struct type which differs between this crate | ||
| // and the other vesion. | ||
| pub fn take_foo(foo: &Foo) -> i32 { | ||
| foo.x + foo.y | ||
| } | ||
|
|
||
| pub fn give_foo() -> Foo { | ||
| Foo { x: 1, y: 2 } | ||
| } | ||
|
|
||
| pub fn get_int() -> i32 { | ||
| // Use a constant to force an MIR GlobalAllocation::Memory | ||
| let zero = &0; | ||
| return *zero | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| [package] | ||
| name = "main" | ||
| version = "0.1.0" | ||
| edition = "2018" | ||
|
|
||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
|
||
| [dependencies] | ||
| dependency1 = { path = "../dependency1" } | ||
| dependency2 = { path = "../dependency2" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| use dependency1; | ||
| use dependency2; | ||
|
|
||
| #[no_mangle] | ||
| fn harness() { | ||
| assert!(dependency1::delegate_get_int() == 0); | ||
| assert!(dependency2::delegate_get_int() == 1); | ||
|
|
||
| assert!(dependency1::delegate_use_struct() == 3); | ||
| assert!(dependency2::delegate_use_struct() == 1); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| # Compile crates with RMC backend | ||
| cd $(dirname $0) | ||
| rm -rf build | ||
|
||
| CARGO_TARGET_DIR=build RUST_BACKTRACE=1 RUSTFLAGS="-Z codegen-backend=gotoc --cfg=rmc" RUSTC=rmc-rustc cargo build | ||
|
|
||
| # Convert from JSON to Gotoc | ||
| cd build/debug/deps/ | ||
| ls *.json | xargs symtab2gb | ||
|
|
||
| # Add the entry point and remove unused functions | ||
| goto-cc --function harness *.out -o a.out | ||
| goto-instrument --drop-unused-functions a.out b.out | ||
|
|
||
| # Run the solver | ||
| RESULT="/tmp/dependency_test_result.txt" | ||
| cbmc b.out &> $RESULT | ||
| if grep -q "VERIFICATION SUCCESSFUL" $RESULT; then | ||
| cat $RESULT | ||
| echo "Successful dependency test" | ||
| exit 0 | ||
| else | ||
| cat $RESULT | ||
| echo "Failed dependency test" | ||
| exit 1 | ||
| fi | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a hack. We should note it as such, and have a tracking issue to do the right thing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed and adding