Skip to content

Commit

Permalink
compiler: fix cross-transpilation is not imitates target architecture…
Browse files Browse the repository at this point in the history
… for architecture-dependent types
  • Loading branch information
mertcandav committed Mar 7, 2024
1 parent a347f36 commit 307cf74
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 193 deletions.
9 changes: 5 additions & 4 deletions src/julec/compile.jule
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::jule::sema::{
SemaFlag,
analyze_package,
}
use std::jule::build::{
use build for std::jule::build::{
self,
LogMsg,
Log,
Expand All @@ -34,6 +34,7 @@ use std::jule::build::{
logf,
is_valid_cpp_ext,
}
use types for std::jule::types
use std::process::{ProcessError, Cmd}
use strings for std::strings

Expand Down Expand Up @@ -271,13 +272,13 @@ fn check_target_flag(&target: str) {

if os != "native" {
check_target_os(os)
env::OS = os
build::OS = os
}

if arch != "native" {
check_target_arch(arch)
env::ARCH = arch
build::ARCH = arch
}
types::update_target()
}

fn check_opt_flag(&opt: str) {
Expand Down
13 changes: 0 additions & 13 deletions src/julec/env/platform.jule

This file was deleted.

29 changes: 18 additions & 11 deletions src/julec/importer/annotation.jule
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.

use env

use path for std::fs::path
use build for std::jule::build
use strings for std::strings
Expand All @@ -13,10 +11,14 @@ fn check_os(arg: str): (ok: bool, exist: bool) {
exist = true

match arg {
| build::Os.Windows: ok = build::is_windows(env::OS)
| build::Os.Darwin: ok = build::is_darwin(env::OS)
| build::Os.Linux: ok = build::is_linux(env::OS)
| build::Os.Unix: ok = build::is_unix(env::OS)
| build::Os.Windows:
ok = build::is_windows(build::OS)
| build::Os.Darwin:
ok = build::is_darwin(build::OS)
| build::Os.Linux:
ok = build::is_linux(build::OS)
| build::Os.Unix:
ok = build::is_unix(build::OS)
|:
ok = true
exist = false
Expand All @@ -30,11 +32,16 @@ fn check_arch(arg: str): (ok: bool, exist: bool) {
exist = true

match arg {
| build::Arch.I386: ok = build::is_i386(env::ARCH)
| build::Arch.Amd64: ok = build::is_amd64(env::ARCH)
| build::Arch.Arm64: ok = build::is_arm64(env::ARCH)
| build::Arch.X64: ok = build::is_64bit(env::ARCH)
| build::Arch.X32: ok = build::is_32bit(env::ARCH)
| build::Arch.I386:
ok = build::is_i386(build::ARCH)
| build::Arch.Amd64:
ok = build::is_amd64(build::ARCH)
| build::Arch.Arm64:
ok = build::is_arm64(build::ARCH)
| build::Arch.X64:
ok = build::is_64bit(build::ARCH)
| build::Arch.X32:
ok = build::is_32bit(build::ARCH)
|:
ok = true
exist = false
Expand Down
37 changes: 16 additions & 21 deletions src/julec/importer/var.jule
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,25 @@

use env

use std::jule::build::{Os, Arch, is_unix, is_32bit, is_64bit}
use build for std::jule::build

pub static mut VARS: []str = nil

// Set operating system variables by native operating system.
fn set_os_vars() {
match env::OS {
| Os.Windows: VARS = append(VARS, "windows")
| Os.Linux: VARS = append(VARS, "linux")
| Os.Darwin: VARS = append(VARS, "darwin")
}

if is_unix(env::OS) {
VARS = append(VARS, build::OS)
if build::is_unix(build::OS) {
VARS = append(VARS, "unix")
}
}

// Set architecture variables by native architecture.
fn set_arch_vars() {
match env::ARCH {
| Arch.I386: VARS = append(VARS, "i386")
| Arch.Amd64: VARS = append(VARS, "amd64")
| Arch.Arm64: VARS = append(VARS, "arm64")
}

if is_64bit(env::ARCH) {
VARS = append(VARS, build::ARCH)
if build::is_64bit(build::ARCH) {
VARS = append(VARS, "x64")
}
if is_32bit(env::ARCH) {
if build::is_32bit(build::ARCH) {
VARS = append(VARS, "x32")
}
}
Expand All @@ -51,13 +41,18 @@ pub fn init_vars() {
}

match env::COMPILER {
| "clang": VARS = append(VARS, "clang")
| "gcc": VARS = append(VARS, "gcc")
| "clang":
VARS = append(VARS, "clang")
| "gcc":
VARS = append(VARS, "gcc")
}

match env::CPP_STD {
| "cpp14": VARS = append(VARS, "cpp14")
| "cpp17": VARS = append(VARS, "cpp17")
| "cpp20": VARS = append(VARS, "cpp20")
| "cpp14":
VARS = append(VARS, "cpp14")
| "cpp17":
VARS = append(VARS, "cpp17")
| "cpp20":
VARS = append(VARS, "cpp20")
}
}
8 changes: 8 additions & 0 deletions std/jule/build/env.jule
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ pub static PATH_EXEC = "" // Path of executable file's directory.
pub static PATH_WD = "" // Path of working directory.
pub static PATH_API = "" // Path of main API header file.

// Target operating system.
// Setted to runtime operating system by default.
pub static mut OS = env::OS

// Target architecture.
// Setted to runtime architecture by default.
pub static mut ARCH = env::ARCH

fn init() {
let mut path = process::executable()
if path == "" {
Expand Down
Loading

0 comments on commit 307cf74

Please sign in to comment.