Skip to content

Latest commit

 

History

History

samples

Running the Samples

Install Bazel using these instructions. If needed, install the C++ toolchain for your platform too. Then compile the library samples using:

bazel build //google/cloud/spanner/samples:samples

On Windows you may need to add some flags to workaround the filename length limits.

You must provide this option in all Bazel invocations shown below.

mkdir C:\b
bazel --output_user_root=C:\b build //google/cloud/spanner/samples:samples

If you are using a Bazel version before 2.2.0 you may need to run the following command to workaround bazelbuild/bazel#10621.

bazel --output_user_root=C:\b test //google/cloud/spanner/samples:samples

On Windows and macOS gRPC requires an environment variable to find the root of trust for SSL. On macOS use:

curl -Lo roots.pem https://pki.google.com/roots.pem
export GRPC_DEFAULT_SSL_ROOTS_FILE_PATH="$PWD/roots.pem"

While on Windows use:

@powershell -NoProfile -ExecutionPolicy unrestricted -Command ^
    (new-object System.Net.WebClient).Downloadfile( ^
        'https://pki.google.com/roots.pem', 'roots.pem')
set GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=%cd%\roots.pem

You will need a Google Cloud Project with billing and the spanner API enabled. Please consult the Spanner quickstart guide for detailed instructions on how to enable billing for your project. Once your project is properly configured you can run the samples using bazel run, for example:

bazel run //google/cloud/spanner/samples:samples -- create-instance [PROJECT ID] [SPANNER INSTANCE] "My Test Instance"
bazel run //google/cloud/spanner/samples:samples -- create-database [PROJECT ID] [SPANNER INSTANCE] [DATABASE ID]

Running the command without options will list the available samples:

bazel run //google/cloud/spanner/samples:samples