Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/common/building/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub fn add_building_env_vars() {
set_env_config().expect("Unable to generate build envs");
add_env_credits_info();
add_target_features();
add_build_profile();
add_opt_level();
add_env_version();
add_env_license();
add_license_public_key();
Expand Down Expand Up @@ -185,3 +187,35 @@ pub fn add_target_features() {
}
};
}

pub fn add_build_profile() {
match env::var_os("PROFILE") {
Some(var) => match var.into_string() {
Ok(s) => println!("cargo:rustc-env=DATABEND_BUILD_PROFILE={}", s),
Err(_) => {
println!("cargo:warning=PROFILE was not valid utf-8");
println!("cargo:rustc-env=DATABEND_BUILD_PROFILE=unknown");
}
},
None => {
println!("cargo:warning=PROFILE was not set");
println!("cargo:rustc-env=DATABEND_BUILD_PROFILE=unknown");
}
};
}

pub fn add_opt_level() {
match env::var_os("OPT_LEVEL") {
Some(var) => match var.into_string() {
Ok(s) => println!("cargo:rustc-env=DATABEND_OPT_LEVEL={}", s),
Err(_) => {
println!("cargo:warning=OPT_LEVEL was not valid utf-8");
println!("cargo:rustc-env=DATABEND_OPT_LEVEL=unknown");
}
},
None => {
println!("cargo:warning=OPT_LEVEL was not set");
println!("cargo:rustc-env=DATABEND_OPT_LEVEL=unknown");
}
};
}
4 changes: 4 additions & 0 deletions src/common/version/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub const DATABEND_ENTERPRISE_LICENSE_PUBLIC_KEY: &str =

pub const DATABEND_CARGO_CFG_TARGET_FEATURE: &str = env!("DATABEND_CARGO_CFG_TARGET_FEATURE");

pub const DATABEND_BUILD_PROFILE: &str = env!("DATABEND_BUILD_PROFILE");

pub const DATABEND_OPT_LEVEL: &str = env!("DATABEND_OPT_LEVEL");

pub const DATABEND_TELEMETRY_ENDPOINT: &str = env!("DATABEND_TELEMETRY_ENDPOINT");

pub const DATABEND_TELEMETRY_API_KEY: &str = env!("DATABEND_TELEMETRY_API_KEY");
Expand Down
52 changes: 52 additions & 0 deletions src/query/service/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::env;

fn main() {
// Keep build script rerun behavior explicit for the feature list we expose.
println!("cargo:rerun-if-env-changed=PROFILE");
println!("cargo:rerun-if-env-changed=OPT_LEVEL");

// Features declared in `src/query/service/Cargo.toml`.
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_SIMD");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_PYTHON_UDF");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_DISABLE_INITIAL_EXEC_TLS");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_JEMALLOC");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_MEMORY_PROFILING");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_STORAGE_HDFS");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_IO_URING");

let mut features = env::vars()
.filter_map(|(k, v)| {
if !k.starts_with("CARGO_FEATURE_") {
return None;
}
Comment on lines +31 to +35

Choose a reason for hiding this comment

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

P1 Badge Wire build.rs into Cargo manifest

The new build script collects query crate features and emits DATABEND_QUERY_CARGO_FEATURES, but src/query/service/Cargo.toml still has no build = "build.rs" entry, so Cargo never executes this script. As a result the environment variable stays unset and system.build_options will always show the cargo features row as not available, defeating the intent of this change in every build profile.

Useful? React with 👍 / 👎.

if v != "1" {
return None;
}
let name = k
.trim_start_matches("CARGO_FEATURE_")
.to_ascii_lowercase()
.replace('_', "-");
Some(name)
})
.collect::<Vec<_>>();

features.sort();
features.dedup();

let features = features.join(",");
println!("cargo:rustc-env=DATABEND_QUERY_CARGO_FEATURES={features}");
}
10 changes: 8 additions & 2 deletions src/query/service/src/databases/system/system_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ use databend_common_storages_system::ViewsTableWithHistory;
use databend_common_storages_system::ViewsTableWithoutHistory;
use databend_common_storages_system::VirtualColumnsTable;
use databend_common_storages_system::ZeroTable;
use databend_common_version::DATABEND_BUILD_PROFILE;
use databend_common_version::DATABEND_CARGO_CFG_TARGET_FEATURE;
use databend_common_version::DATABEND_COMMIT_AUTHORS;
use databend_common_version::DATABEND_CREDITS_LICENSES;
use databend_common_version::DATABEND_CREDITS_NAMES;
use databend_common_version::DATABEND_CREDITS_VERSIONS;
use databend_common_version::VERGEN_CARGO_FEATURES;
use databend_common_version::DATABEND_OPT_LEVEL;

use crate::catalogs::InMemoryMetas;
use crate::databases::Database;
Expand All @@ -89,6 +90,9 @@ pub struct SystemDatabase {
db_info: DatabaseInfo,
}

const DATABEND_QUERY_CARGO_FEATURES: Option<&'static str> =
option_env!("DATABEND_QUERY_CARGO_FEATURES");

impl SystemDatabase {
/// These tables may disabled to the sql users.
fn disable_system_tables() -> HashMap<String, bool> {
Expand Down Expand Up @@ -152,8 +156,10 @@ impl SystemDatabase {
DatabasesTableWithHistory::create(sys_db_meta.next_table_id(), ctl_name),
BuildOptionsTable::create(
sys_db_meta.next_table_id(),
VERGEN_CARGO_FEATURES,
DATABEND_QUERY_CARGO_FEATURES,
DATABEND_CARGO_CFG_TARGET_FEATURE,
DATABEND_BUILD_PROFILE,
DATABEND_OPT_LEVEL,
),
QueryCacheTable::create(sys_db_meta.next_table_id()),
TableFunctionsTable::create(sys_db_meta.next_table_id()),
Expand Down
16 changes: 11 additions & 5 deletions src/query/service/tests/it/storages/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ use databend_common_storages_system::MetricsTable;
use databend_common_storages_system::RolesTable;
use databend_common_storages_system::UsersTable;
use databend_common_users::UserApiProvider;
use databend_common_version::DATABEND_BUILD_PROFILE;
use databend_common_version::DATABEND_CARGO_CFG_TARGET_FEATURE;
use databend_common_version::DATABEND_COMMIT_AUTHORS;
use databend_common_version::DATABEND_CREDITS_LICENSES;
use databend_common_version::DATABEND_CREDITS_NAMES;
use databend_common_version::DATABEND_CREDITS_VERSIONS;
use databend_common_version::VERGEN_CARGO_FEATURES;
use databend_common_version::DATABEND_OPT_LEVEL;
use databend_query::sessions::QueryContext;
use databend_query::sessions::TableContext;
use databend_query::stream::ReadDataBlockStream;
Expand Down Expand Up @@ -113,17 +114,22 @@ async fn test_build_options_table() -> Result<()> {
let fixture = TestFixture::setup().await?;
let ctx = fixture.new_query_ctx().await?;

let table =
BuildOptionsTable::create(1, VERGEN_CARGO_FEATURES, DATABEND_CARGO_CFG_TARGET_FEATURE);
let table = BuildOptionsTable::create(
1,
option_env!("DATABEND_QUERY_CARGO_FEATURES"),
DATABEND_CARGO_CFG_TARGET_FEATURE,
DATABEND_BUILD_PROFILE,
DATABEND_OPT_LEVEL,
);
let source_plan = table
.read_plan(ctx.clone(), None, None, false, true)
.await?;

let stream = table.read_data_block_stream(ctx, &source_plan).await?;
let result = stream.try_collect::<Vec<_>>().await?;
let block = &result[0];
assert_eq!(block.num_columns(), 2);
assert!(block.num_rows() > 0);
assert_eq!(block.num_columns(), 3);
assert!(block.num_rows() >= 4);

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ DB.Table: 'system'.'columns', Table: columns-table_id:1, ver:0, Engine: SystemCo
| 'byte_size' | 'system' | 'clustering_history' | 'UInt64' | 'BIGINT UNSIGNED' | '' | '' | 'NO' | '' |
| 'capacity' | 'system' | 'caches' | 'UInt64' | 'BIGINT UNSIGNED' | '' | '' | 'NO' | '' |
| 'cardinality' | 'information_schema' | 'statistics' | 'NULL' | 'NULL' | '' | '' | 'NO' | '' |
| 'cargo_features' | 'system' | 'build_options' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'catalog' | 'system' | 'databases' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'catalog' | 'system' | 'databases_with_history' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'catalog' | 'system' | 'streams' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
Expand All @@ -34,6 +33,7 @@ DB.Table: 'system'.'columns', Table: columns-table_id:1, ver:0, Engine: SystemCo
| 'catalog' | 'system' | 'views' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'catalog' | 'system' | 'views_with_history' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'catalog_name' | 'information_schema' | 'schemata' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'category' | 'system' | 'build_options' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'character_maximum_length' | 'information_schema' | 'columns' | 'Nullable(UInt16)' | 'SMALLINT UNSIGNED' | '' | '' | 'YES' | '' |
| 'character_octet_length' | 'information_schema' | 'columns' | 'Nullable(UInt16)' | 'SMALLINT UNSIGNED' | '' | '' | 'YES' | '' |
| 'character_set_catalog' | 'information_schema' | 'columns' | 'NULL' | 'NULL' | '' | '' | 'NO' | '' |
Expand Down Expand Up @@ -265,6 +265,7 @@ DB.Table: 'system'.'columns', Table: columns-table_id:1, ver:0, Engine: SystemCo
| 'mode' | 'system' | 'streams_terse' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'must_change_password' | 'system' | 'users' | 'Nullable(Boolean)' | 'BOOLEAN' | '' | '' | 'YES' | '' |
| 'mysql_connection_id' | 'system' | 'processes' | 'Nullable(UInt32)' | 'INT UNSIGNED' | '' | '' | 'YES' | '' |
| 'name' | 'system' | 'build_options' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'name' | 'system' | 'caches' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'name' | 'system' | 'catalogs' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'name' | 'system' | 'clusters' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
Expand Down Expand Up @@ -445,7 +446,6 @@ DB.Table: 'system'.'columns', Table: columns-table_id:1, ver:0, Engine: SystemCo
| 'table_type' | 'system' | 'tables' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'table_type' | 'system' | 'tables_with_history' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'table_version' | 'system' | 'streams' | 'Nullable(UInt64)' | 'BIGINT UNSIGNED' | '' | '' | 'YES' | '' |
| 'target_features' | 'system' | 'build_options' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'time' | 'system' | 'processes' | 'UInt64' | 'BIGINT UNSIGNED' | '' | '' | 'NO' | '' |
| 'timestamp' | 'system' | 'query_execution' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
| 'total_columns' | 'system' | 'tables' | 'UInt64' | 'BIGINT UNSIGNED' | '' | '' | 'NO' | '' |
Expand Down Expand Up @@ -478,6 +478,7 @@ DB.Table: 'system'.'columns', Table: columns-table_id:1, ver:0, Engine: SystemCo
| 'user' | 'system' | 'locks' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'user' | 'system' | 'processes' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'user' | 'system' | 'temporary_tables' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'value' | 'system' | 'build_options' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'value' | 'system' | 'configs' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'value' | 'system' | 'malloc_stats_totals' | 'UInt64' | 'BIGINT UNSIGNED' | '' | '' | 'NO' | '' |
| 'value' | 'system' | 'metrics' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
Expand All @@ -499,5 +500,3 @@ DB.Table: 'system'.'columns', Table: columns-table_id:1, ver:0, Engine: SystemCo
| 'webhook_options' | 'system' | 'notifications' | 'Nullable(Variant)' | 'VARIANT' | '' | '' | 'YES' | '' |
| 'workload_groups' | 'system' | 'users' | 'Nullable(String)' | 'VARCHAR' | '' | '' | 'YES' | '' |
+-----------------------------------+----------------------+---------------------------+-----------------------+---------------------+----------+----------+----------+----------+


52 changes: 34 additions & 18 deletions src/query/storages/system/src/build_options_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::cmp::max;
use std::sync::Arc;

use databend_common_catalog::table::Table;
Expand Down Expand Up @@ -53,10 +52,13 @@ impl BuildOptionsTable {
table_id: u64,
cargo_features: Option<&str>,
target_features: &str,
build_profile: &str,
opt_level: &str,
) -> Arc<dyn Table> {
let schema = TableSchemaRefExt::create(vec![
TableField::new("cargo_features", TableDataType::String),
TableField::new("target_features", TableDataType::String),
TableField::new("category", TableDataType::String),
TableField::new("name", TableDataType::String),
TableField::new("value", TableDataType::String),
]);

let table_info = TableInfo {
Expand All @@ -71,28 +73,42 @@ impl BuildOptionsTable {
..Default::default()
};

let mut cargo_features = if let Some(features) = cargo_features {
features
.split_terminator(',')
.map(|x| x.trim().to_string())
.collect::<Vec<_>>()
let cargo_features = cargo_features
.map(|s| s.trim())
.filter(|s| !s.is_empty())
.unwrap_or("not available");

let target_features = target_features.trim();
let target_features = if target_features.is_empty() {
"not available"
} else {
vec!["not available".to_string()]
target_features
};

let mut target_features: Vec<String> = target_features
.split_terminator(',')
.map(|x| x.trim().to_string())
.collect();
let mut category = Vec::with_capacity(4);
let mut name = Vec::with_capacity(4);
let mut value = Vec::with_capacity(4);

category.push("cargo".to_string());
name.push("features".to_string());
value.push(cargo_features.to_string());

category.push("target".to_string());
name.push("features".to_string());
value.push(target_features.to_string());

let length = max(cargo_features.len(), target_features.len());
category.push("cargo".to_string());
name.push("build_profile".to_string());
value.push(build_profile.to_string());

cargo_features.resize(length, "".to_string());
target_features.resize(length, "".to_string());
category.push("cargo".to_string());
name.push("opt_level".to_string());
value.push(opt_level.to_string());

let data = DataBlock::new_from_columns(vec![
StringType::from_data(cargo_features),
StringType::from_data(target_features),
StringType::from_data(category),
StringType::from_data(name),
StringType::from_data(value),
]);

SyncOneBlockSystemTable::create(BuildOptionsTable { table_info, data })
Expand Down