sdk: Make PubKey::create_program_address available in program unit tests (bp #11745) (#11809)

* sdk: Make PubKey::create_program_address available in program unit tests (#11745)

* sdk: Make PubKey::create_program_address available in program unit tests

This finishes the work started in #11604 to have
`create_program_address` available when `target_arch` is not `bpf` and
`program` is enabled.  Otherwise, there is an undefined reference error
to `sol_create_program_address`, which is only defined in `bpf`.

A small test to simply call the function has been added in order to catch
the problem in the future.

The default dependency to `solana-sdk/default` doesn't cause a problem with
existing programs since `build.sh` always specifies
`--no-default-features`, and programs in `solana-program-library` all
use it too.

* Add `default-features = false` for inter-program dependencies

Fix the build error found during CI.  The `--no-default-features` flag
only applies to the top-level package, and not to dependencies.  A program that
depends on another program, i.e. `128bit` which depends on `128bit_dep`,
must specify `default-features = false` when including that package,
otherwise the `bpf` build will try to pull in default packages, which
includes `std`.

(cherry picked from commit 9a366281d3)

# Conflicts:
#	programs/bpf/rust/128bit/Cargo.toml
#	programs/bpf/rust/invoke/Cargo.toml
#	programs/bpf/rust/many_args/Cargo.toml
#	programs/bpf/rust/param_passing/Cargo.toml

* Fix merge conflicts

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
This commit is contained in:
mergify[bot]
2020-08-24 21:30:15 +00:00
committed by GitHub
parent 8d67204123
commit de4e548105
19 changed files with 41 additions and 29 deletions

View File

@@ -1,6 +1,6 @@
#[cfg(feature = "program")]
#[cfg(all(feature = "program", target_arch = "bpf"))]
use crate::entrypoint::SUCCESS;
#[cfg(not(feature = "program"))]
#[cfg(not(all(feature = "program", target_arch = "bpf")))]
use crate::hash::Hasher;
use crate::{decode_error::DecodeError, hash::hashv};
use num_derive::{FromPrimitive, ToPrimitive};
@@ -104,7 +104,7 @@ impl Pubkey {
) -> Result<Pubkey, PubkeyError> {
// Perform the calculation inline, calling this from within a program is
// not supported
#[cfg(not(feature = "program"))]
#[cfg(not(all(feature = "program", target_arch = "bpf")))]
{
let mut hasher = Hasher::default();
for seed in seeds.iter() {
@@ -126,7 +126,7 @@ impl Pubkey {
Ok(Pubkey::new(hash.as_ref()))
}
// Call via a system call to perform the calculation
#[cfg(feature = "program")]
#[cfg(all(feature = "program", target_arch = "bpf"))]
{
extern "C" {
fn sol_create_program_address(