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

Configurable architecture #65

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions include/bake/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef struct bake_repository {
struct bake_config {
const char *environment; /* Id of environment in use */
const char *configuration; /* Id of configuration in use */
const char *architecture; /* Id of architecture in use */

/* Configuration attributes */
bool symbols; /* Enable symbols in binaries */
Expand Down
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ int16_t bake_config_load(

/* Precompute bake paths */
cfg_out->configuration = ut_strdup(UT_CONFIG);
cfg_out->architecture = "x86";
cfg_out->platform = UT_PLATFORM_PATH;
cfg_out->target = UT_TARGET_PATH;
cfg_out->home = UT_HOME_PATH;
Expand Down
6 changes: 5 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ut_tls BAKE_CONFIG_KEY;

/* Bake configuration */
const char *cfg = NULL;
const char *arch = NULL;
const char *env = "default";
const char *action = "build";
const char *path = ".";
Expand Down Expand Up @@ -94,6 +95,7 @@ void bake_usage(void)
printf(" -v,--version Display version information\n");
printf("\n");
printf(" --cfg <configuration> Specify configuration id\n");
printf(" --arch <architecture> Specify architecture id\n");
printf(" --env <environment> Specify environment id\n");
printf(" --strict Manually enable strict compiler options\n");
printf(" --optimize Manually enable compiler optimizations\n");
Expand Down Expand Up @@ -284,6 +286,7 @@ int bake_parse_args(
bool parsed = false;
ARG(0, "env", env = argv[i + 1]; i ++);
ARG(0, "cfg", cfg = argv[i + 1]; i ++);
ARG(0, "arch", arch = argv[i + 1]; i ++);
ARG(0, "strict", strict = true;);
ARG(0, "optimize", optimize = true; i ++);

Expand Down Expand Up @@ -1340,7 +1343,7 @@ int main(int argc, const char *argv[]) {
ut_log_push("init");

/* Initialize package loader for default home, arch, os and config */
ut_load_init(NULL, NULL, NULL, cfg);
ut_load_init(NULL, arch, NULL, cfg);

/* If artefact is manually specified, translate to platform specific name */
if (artefact) {
Expand All @@ -1363,6 +1366,7 @@ int main(int argc, const char *argv[]) {
bake_config config = {
.configuration = UT_CONFIG,
.environment = env,
.architecture = arch,
.symbols = true,
.debug = true,
.optimizations = false,
Expand Down
18 changes: 9 additions & 9 deletions src/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ int16_t bake_create_upgrade_script(void)
}

/* Create bake script for Windows */
int16_t bake_create_script(bool local)
int16_t bake_create_script(bool local, const char* architecture)
{
char *script_path = ut_envparse(BAKE_SCRIPT);
if (!script_path) {
ut_error("failed to open '%s'", BAKE_SCRIPT);
goto error;
}

char *vc_shell_cmd = ut_get_vc_shell_cmd();
char *vc_shell_cmd = ut_get_vc_shell_cmd(architecture);

FILE *f = fopen(script_path, "wb");
if (!f) {
Expand Down Expand Up @@ -216,7 +216,7 @@ int16_t bake_create_upgrade_script(void)
}

/* Install script to global location that invokes local bake executable */
int16_t bake_create_script(bool local)
int16_t bake_create_script(bool local, const char* architecture)
{
if (local) {
return 0;
Expand Down Expand Up @@ -277,6 +277,7 @@ int16_t bake_create_script(bool local)

/* Utility function to bootstrap a bake project while bake is installing */
int16_t bake_build_make_project(
bake_config *config,
const char *path,
const char *id,
const char *artefact)
Expand Down Expand Up @@ -314,8 +315,7 @@ int16_t bake_build_make_project(
bake_message(UT_OK, "done", "build '%s'", id);

/* Create the bake bin path (makefiles copy binary to project root) */
char *bin_path = ut_asprintf(
"%s"UT_OS_PS"bin"UT_OS_PS"%s-debug", path, UT_PLATFORM_STRING);
char *bin_path = ut_asprintf("%s"UT_OS_PS"bin"UT_OS_PS"%s-%s", path, UT_PLATFORM_STRING, config->configuration);
ut_try(ut_mkdir(bin_path), "failed to create bin path for %s", id);

/* Move binary from project root to bake bin path */
Expand Down Expand Up @@ -407,7 +407,7 @@ int16_t bake_setup(

/* Create the global bake script, which allows for invoking bake without
* first exporting the environment */
ut_try( bake_create_script(local),
ut_try( bake_create_script(local, config->architecture),
"failed to create global bake script, rerun setup with --local");

/* Copy bake executable to bake environment in user working directory */
Expand All @@ -426,13 +426,13 @@ int16_t bake_setup(
bake_message(UT_OK, "done", "install bake include files");

/* Build bake util */
ut_try( bake_build_make_project("util", "bake.util", "bake_util"), NULL);
ut_try( bake_build_make_project(config, "util", "bake.util", "bake_util"), NULL);

/* Build the C and C++ drivers */
ut_try( bake_build_make_project("drivers"UT_OS_PS"lang"UT_OS_PS"c",
ut_try( bake_build_make_project(config, "drivers"UT_OS_PS"lang"UT_OS_PS"c",
"bake.lang.c", "bake_lang_c"), NULL);

ut_try( bake_build_make_project("drivers"UT_OS_PS"lang"UT_OS_PS"cpp",
ut_try( bake_build_make_project(config, "drivers"UT_OS_PS"lang"UT_OS_PS"cpp",
"bake.lang.cpp", "bake_lang_cpp"), NULL);

/* Build the bake test framework */
Expand Down
2 changes: 1 addition & 1 deletion util/include/bake-util/win/vs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C" {

UT_EXPORT char * ut_get_vs_dir();

UT_EXPORT char * ut_get_vc_shell_cmd();
UT_EXPORT char * ut_get_vc_shell_cmd(const char* architecture);

const char* ut_last_win_error_code(DWORD dw);

Expand Down
4 changes: 2 additions & 2 deletions util/src/win/vs.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ char * ut_get_vs_dir()
return vs_path_env;
}

char * ut_get_vc_shell_cmd()
char * ut_get_vc_shell_cmd(const char* architecture)
{
char * vs_path_env = ut_get_vs_dir();
if (vs_path_env[strlen(vs_path_env) - 1] == '\\')
vs_path_env[strlen(vs_path_env) - 1] = '\0';
char * vc_shell = ut_asprintf("%s\\VC\\Auxiliary\\Build\\vcvarsall.bat", vs_path_env);
// Check file path exist
char * vc_shell_cmd = ut_asprintf("call \"%s\" x64", vc_shell);
char * vc_shell_cmd = ut_asprintf("call \"%s\" %s", vc_shell, architecture);
return vc_shell_cmd;
}