Skip to content

Commit 8c650b5

Browse files
committed
cleanup
1 parent 83e5de0 commit 8c650b5

File tree

2 files changed

+68
-19
lines changed

2 files changed

+68
-19
lines changed

packages/std/sdk/proxy.tg.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,19 @@ const ldProxy = async (arg: LdProxyArg) => {
272272
const host = arg.host ?? (await std.triple.host());
273273
const build = arg.build ?? host;
274274
const buildToolchain = arg.buildToolchain;
275-
const embedWrapper = arg.embedWrapper ?? true;
275+
const embedWrapper = arg.embedWrapper ?? std.triple.os(build) === "linux";
276276

277277
// Get the embedded wrapper artifacts.
278-
const stubArtifacts = await stub.workspace(arg);
279-
const wrapBin = await stubArtifacts.get("wrap");
280-
const stubBin = await stubArtifacts.get("stub.bin");
281-
const stubElf = await stubArtifacts.get("stub.elf");
282-
283-
// Obtain wrapper components.
278+
let wrapBin = undefined;
279+
let stubBin = undefined;
280+
let stubElf = undefined;
281+
282+
if (std.triple.os(build) === "linux") {
283+
const stub_ = await stub.workspace(arg);
284+
wrapBin = await stub_.get("wrap");
285+
stubBin = await stub_.get("stub.bin");
286+
stubElf = await stub_.get("stub.elf");
287+
}
284288

285289
// The linker proxy is built for the build machine.
286290
const buildLinkerProxy = await workspace.ldProxy({
@@ -313,9 +317,13 @@ const ldProxy = async (arg: LdProxyArg) => {
313317
arg.interpreter ?? "none",
314318
),
315319
TANGRAM_WRAPPER_ID: tg.Mutation.setIfUnset(hostWrapper.id),
316-
TANGRAM_STUB_BIN_ID: tg.Mutation.setIfUnset(stubBin.id),
317-
TANGRAM_STUB_ELF_ID: tg.Mutation.setIfUnset(stubElf.id),
318-
TANGRAM_WRAP_ID: tg.Mutation.setIfUnset(wrapBin.id),
320+
TANGRAM_STUB_BIN_ID: stubBin
321+
? tg.Mutation.setIfUnset(stubBin.id)
322+
: undefined,
323+
TANGRAM_STUB_ELF_ID: stubElf
324+
? tg.Mutation.setIfUnset(stubElf.id)
325+
: undefined,
326+
TANGRAM_WRAP_ID: wrapBin ? tg.Mutation.setIfUnset(wrapBin.id) : undefined,
319327
TANGRAM_LINKER_EMBED_WRAPPER: embedWrapper
320328
? tg.Mutation.setIfUnset("true")
321329
: undefined,

packages/std/wrap/stub.tg.ts

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import * as ogWorkspace from "./workspace.tg.ts";
66
import packages from "../packages" with { type: "directory" };
77

88
type WorkspaceArg = {
9-
build?: string;
109
host?: string;
10+
target?: string;
1111
release?: boolean;
1212
source?: tg.Directory;
1313
verbose?: boolean;
@@ -48,22 +48,27 @@ export const embedWrapper = async (arg: WrapArg) => {
4848

4949
export const workspace = async (arg: WorkspaceArg) => {
5050
const {
51-
build: build_,
51+
target: target_,
5252
host: host_,
5353
release = true,
5454
source: source_,
5555
verbose = false,
5656
} = await tg.resolve(arg);
5757
const host = host_ ?? (await std.triple.host());
58-
const buildTriple = build_ ?? host;
58+
59+
// Ensure we're only building for Linux.
60+
const target = target_ ?? host;
61+
62+
if (std.triple.os(target) !== "linux") {
63+
throw new Error("embeded wrapper support is limited to linux targets");
64+
}
5965

6066
// Get the source.
6167
const source: tg.Directory = source_ ? source_ : packages;
6268
return build({
63-
// buildToolchain,
6469
host,
6570
verbose,
66-
target: buildTriple,
71+
target,
6772
source,
6873
}).then(tg.Directory.expect);
6974
};
@@ -249,11 +254,47 @@ export const testCompile = async () => {
249254
}
250255
return 0;
251256
}
252-
`)
257+
`),
253258
});
254259
return std.run`
255260
gcc ${source}/main.c -o $OUTPUT
256261
`
257-
.bootstrap(true)
258-
.env(toolchain, { utils: false }, { TANGRAM_TRACING: "true" });
259-
}
262+
.bootstrap(true)
263+
.env(
264+
toolchain,
265+
{ utils: false },
266+
{
267+
TANGRAM_TRACING: "true",
268+
TANGRAM_LINKER_TRACING: "tangram_ld_proxy=trace",
269+
},
270+
);
271+
};
272+
273+
export const testFull = async () => {
274+
const toolchain = std.sdk();
275+
const source = tg.directory({
276+
"main.c": tg.file(`
277+
#include <stdio.h>
278+
extern char** environ;
279+
int main(int argc, const char** argv) {
280+
for (int i = 0; i < 2; i++) {
281+
const char* var = i ? "envp" : "argv";
282+
const char** s = i ? (const char**)environ : argv;
283+
int j = 0;
284+
for (; *s; s++, j++) {
285+
printf("%s[%d] = %s\\n", var, j, *s);
286+
}
287+
}
288+
return 0;
289+
}
290+
`),
291+
});
292+
let file = std.$`
293+
gcc ${source}/main.c -o $OUTPUT
294+
`
295+
.env(toolchain, { utils: false }, { TANGRAM_TRACING: "true" })
296+
.then(tg.File.expect);
297+
return std.wrap(file, {
298+
env: { CUSTOM_ENV: "true", TANGRAM_SUPPRESS_ENV: "true" },
299+
});
300+
};

0 commit comments

Comments
 (0)