mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 15:27:45 +03:00
Merge branch 'trunk' into nixfmt
This commit is contained in:
commit
1024ee0ce3
7
.github/workflows/nix.yml
vendored
7
.github/workflows/nix.yml
vendored
@ -21,5 +21,8 @@ jobs:
|
||||
with:
|
||||
clean: "true"
|
||||
|
||||
- name: setup dependencies with nix, build and test
|
||||
run: nix develop -c cargo test --locked --release --no-run
|
||||
- name: setup dependencies with nix and build the tests
|
||||
run: nix develop -c cargo test --locked --release --no-run
|
||||
|
||||
- name: execute tests with guaranteed success
|
||||
run: nix develop -c cargo test --locked --release --no-fail-fast || true # || true to return a successful exit code so that test failures can be observed
|
||||
|
@ -361,11 +361,12 @@ pub fn build_swift_host_native(
|
||||
unimplemented!("Linking a shared library to Swift not yet implemented");
|
||||
}
|
||||
|
||||
let mut command = Command::new("swiftc");
|
||||
let mut command = Command::new("xcrun"); // xcrun helps swiftc to find the right header files
|
||||
command
|
||||
.env_clear()
|
||||
.env("PATH", &env_path)
|
||||
.env("HOME", &env_home)
|
||||
.arg("swiftc")
|
||||
.args(sources)
|
||||
.arg("-emit-object")
|
||||
.arg("-parse-as-library")
|
||||
|
@ -6,4 +6,4 @@ struct RocStr {
|
||||
size_t capacity;
|
||||
};
|
||||
|
||||
extern struct RocStr roc__mainForHost_1_exposed();
|
||||
extern void roc__mainForHost_1_exposed_generic(const struct RocStr *data);
|
||||
|
@ -21,39 +21,42 @@ func rocRealloc(ptr: UInt, _oldSize: Int, newSize: Int, _alignment: UInt) -> UIn
|
||||
return UInt(bitPattern: ptr)
|
||||
}
|
||||
|
||||
extension RocStr {
|
||||
var isSmallString: Bool {
|
||||
capacity < 0
|
||||
}
|
||||
func isSmallString(rocStr: RocStr) -> Bool {
|
||||
return rocStr.capacity < 0
|
||||
}
|
||||
|
||||
var length: Int {
|
||||
if isSmallString {
|
||||
// Small String length is last in the byte of capacity.
|
||||
var cap = capacity
|
||||
let count = MemoryLayout.size(ofValue: cap)
|
||||
let bytes = Data(bytes: &cap, count: count)
|
||||
let lastByte = bytes[count - 1]
|
||||
return Int(lastByte ^ 0b1000_0000)
|
||||
} else {
|
||||
return len
|
||||
}
|
||||
func getStrLen(rocStr: RocStr) -> Int {
|
||||
if isSmallString(rocStr: rocStr) {
|
||||
// Small String length is last in the byte of capacity.
|
||||
var cap = rocStr.capacity
|
||||
let count = MemoryLayout.size(ofValue: cap)
|
||||
let bytes = Data(bytes: &cap, count: count)
|
||||
let lastByte = bytes[count - 1]
|
||||
return Int(lastByte ^ 0b1000_0000)
|
||||
} else {
|
||||
return rocStr.len
|
||||
}
|
||||
}
|
||||
|
||||
var string: String {
|
||||
if isSmallString {
|
||||
let data: Data = withUnsafePointer(to: self) { ptr in
|
||||
Data(bytes: ptr, count: length)
|
||||
}
|
||||
return String(data: data, encoding: .utf8)!
|
||||
} else {
|
||||
let data = Data(bytes: bytes, count: len)
|
||||
return String(data: data, encoding: .utf8)!
|
||||
func getSwiftString(rocStr: RocStr) -> String {
|
||||
let length = getStrLen(rocStr: rocStr)
|
||||
|
||||
if isSmallString(rocStr: rocStr) {
|
||||
let data: Data = withUnsafePointer(to: rocStr) { ptr in
|
||||
Data(bytes: ptr, count: length)
|
||||
}
|
||||
return String(data: data, encoding: .utf8)!
|
||||
} else {
|
||||
let data = Data(bytes: rocStr.bytes, count: length)
|
||||
return String(data: data, encoding: .utf8)!
|
||||
}
|
||||
}
|
||||
|
||||
@_cdecl("main")
|
||||
func main() -> UInt8 {
|
||||
print(roc__mainForHost_1_exposed().string, terminator: "")
|
||||
var rocStr = RocStr()
|
||||
roc__mainForHost_1_exposed_generic(&rocStr)
|
||||
|
||||
print(getSwiftString(rocStr: rocStr), terminator: "")
|
||||
return 0
|
||||
}
|
||||
|
@ -110,7 +110,6 @@
|
||||
lib.makeLibraryPath
|
||||
([ pkg-config stdenv.cc.cc.lib libffi ncurses zlib ] ++ linuxInputs);
|
||||
NIXPKGS_ALLOW_UNFREE = 1; # to run the editor with NVIDIA's closed source drivers
|
||||
ZIG_GLOBAL_CACHE_DIR = if pkgs.stdenv.isDarwin then "${builtins.getEnv "TMPDIR"}" else ""; # workaround for github.com/ziglang/zig/issues/9711
|
||||
};
|
||||
|
||||
formatter = pkgs.nixpkgs-fmt;
|
||||
|
Loading…
Reference in New Issue
Block a user